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>

//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;)
var fruitname=fruits[i];
// 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


function fun()
// 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...


<body onload="fun()">
<p id="demo">Click the button </p>
<button onclick="myFunction('Apple')">Try it</button>

Recommended Answers

All 3 Replies

Hi Venter,

Here you are :)

for (var i=0;i<fruits.length; i++)

Let me know if you have questions.

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

You're most welcome. :)

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.