We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,506 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Hello Good AfterNoon To all Small Help Needed

Hi i'm trying to save the data in local storage.But it Works Correctly As My code.But i want to save the data in different Manner. Here is my code Snippet Walk Through It And MAke Corrections....

<!DOCTYPE html>
<html>
<head>
<script>

//function for \to check whether the input value is exists in array or not
function myFunction(x)
{
var y=x;
var fruits = ["Banana", "Orange", "Apple", "Mango"];

for (var i=0;i<fruits.length;)
{
if(fruits[i]==y)
{
var fruitname=fruits[i];
localStorage.fruitname="SELECTED";
// here  localStorage.fruitname was treating as new variable
//but my requirement is i want to place the value of fruitname after localStorage.fruitname[value] is it possible..
//please correct my code..thank u all
}
i++;
}
alert(localStorage.fruitname);

}

function fun()
{
alert(localStorage.Apple);
// here it will displaying alert as 'undefined'.
// wen i change my code as "alert(localStorage.fruitname);"
// it was dispalying  alert as 'SELECTED' my requirement is i want to dispaly the alert(localstorage.Apple) as SELECTED...
}


</script>

</head>
<body onload="fun()">
<p id="demo">Click the button </p>
<button onclick="myFunction('Apple')">Try it</button>
</body>
</html>
2
Contributors
3
Replies
4 Hours
Discussion Span
3 Months Ago
Last Updated
4
Views
Venter
Light Poster
25 posts since Oct 2012
Reputation Points: -2
Solved Threads: 0
Skill Endorsements: 0

Hi Venter,

Here you are :)

for (var i=0;i<fruits.length; i++)
{
    if(fruits[i]==y)
    {
        localStorage[fruits[i]]="SELECTED";
    }
}

Let me know if you have questions.

gon1387
Posting Whiz in Training
233 posts since Jan 2011
Reputation Points: 32
Solved Threads: 37
Skill Endorsements: 3

Thank u Gon.Many Many Thanksss Buddyyyyyyyyyyyyyyyyyyyyy...............

Venter
Light Poster
25 posts since Oct 2012
Reputation Points: -2
Solved Threads: 0
Skill Endorsements: 0

You're most welcome. :)

NOTE: Please mark the thread as solve if the query's been answered.

gon1387
Posting Whiz in Training
233 posts since Jan 2011
Reputation Points: 32
Solved Threads: 37
Skill Endorsements: 3

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.1070 seconds using 2.67MB