Catalyst Creations
Posts: 0
Joined: Sat Dec 28, 2013 1:34 am

How would I set a input value to local storage using JavaScript if value is above 0?

Hey guys,

I have 10 inputs been stored to local storage with click action. I need to set to local storage only when the value of input field is more than 0? how would I go about this? javascript on click event seems the option but how would I set to local if value above 0 using Jscript? ive got this far - localStorage.setItem('Storage Variable', "Input text"); and to use a if statement is where I get lost..

Igor
Posts: 0
Joined: Tue Apr 02, 2013 12:05 pm

How would I set a input value to local storage using JavaScript if value is above 0?

Hello,

Please try below code:
pre
code
var val = Appery("mobiletextinput_10").val();
if (val!=0) {
localStorage.setItem("variableName", val);
}
/code
/pre
where "mobiletextinput_10" - input component name.

Catalyst Creations
Posts: 0
Joined: Sat Dec 28, 2013 1:34 am

How would I set a input value to local storage using JavaScript if value is above 0?

Hey Igor,

Thank you that worked perfect..

Catalyst Creations
Posts: 0
Joined: Sat Dec 28, 2013 1:34 am

How would I set a input value to local storage using JavaScript if value is above 0?

hey Igor,

Just a query, ive used the below code but its not setting the value to local storage? is it because I am getting the value from a label component?? code -

var val = Appery("Item1").val();
if (val!="----") {
localStorage.setItem("Item1", val);
} else {
localStorage.setItem("Item1", "");
}

Igor
Posts: 0
Joined: Tue Apr 02, 2013 12:05 pm

How would I set a input value to local storage using JavaScript if value is above 0?

You could add codeconsole.log()/code and check browser console to make sure that val variable return correct value.

precode
var val = Appery("Item1").val();
console.log("item1 value: " + val);
...
/code/pre
This should be helpful:
http://docs.appery.io/documentation/d...
http://www.w3schools.com/js/js_compar...

Catalyst Creations
Posts: 0
Joined: Sat Dec 28, 2013 1:34 am

How would I set a input value to local storage using JavaScript if value is above 0?

all good Igor, Forgot to change .val to .text
Cheers

LuisMa Suárez Gutiérrez
Posts: 0
Joined: Mon Aug 18, 2014 9:12 pm

How would I set a input value to local storage using JavaScript if value is above 0?

how can i know if i need val or text? is there a rule?

Return to “Issues”