Page 1 of 1
How would I set a input value to local storage using JavaScript if value is above 0?
Posted: Sat Mar 08, 2014 2:25 am
by Catalyst Creations
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..
How would I set a input value to local storage using JavaScript if value is above 0?
Posted: Sat Mar 08, 2014 2:56 am
by Igor
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.
How would I set a input value to local storage using JavaScript if value is above 0?
Posted: Sat Mar 08, 2014 4:52 am
by Catalyst Creations
Hey Igor,
Thank you that worked perfect..
How would I set a input value to local storage using JavaScript if value is above 0?
Posted: Sat Mar 08, 2014 5:29 am
by Catalyst Creations
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", "");
}
How would I set a input value to local storage using JavaScript if value is above 0?
Posted: Sat Mar 08, 2014 5:48 am
by Igor
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...
How would I set a input value to local storage using JavaScript if value is above 0?
Posted: Sat Mar 08, 2014 5:58 am
by Catalyst Creations
all good Igor, Forgot to change .val to .text
Cheers
How would I set a input value to local storage using JavaScript if value is above 0?
Posted: Sun Jun 07, 2015 5:31 am
by LuisMa Suárez Gutiérrez
how can i know if i need val or text? is there a rule?