Page 1 of 2

Beginner needs help using javascript to manipulate a string value

Posted: Sat Feb 15, 2014 8:04 pm
by Todd Penny6646042

This may be a silly question but I am trying to edit a string which is stored as a local variable when a button is clicked. This is the code I am using, there is no error message, it just does not work.

Handler: inputTextLocal = inputTextLocal.substring(1,4);

Any help appreciated!


Beginner needs help using javascript to manipulate a string value

Posted: Sat Feb 15, 2014 8:34 pm
by Alena Prykhodko

Hi Todd,

It can be done a little easier:

On Click event use Set property action for input component ( http://docs.appery.io/documentation/w...)
Tick Read from local storage variable and choose value (variable's name).


Beginner needs help using javascript to manipulate a string value

Posted: Sat Feb 15, 2014 9:35 pm
by Todd Penny6646042

I am not sure this is what I need. I need to be able to edit an input string using substring. So I think I need to run a javascript to make the change to the input string if that makes sense?


Beginner needs help using javascript to manipulate a string value

Posted: Sat Feb 15, 2014 10:26 pm
by Igor

Hello,

You could add alert() function to make sure that your code is executed and it returns some value. Please try to use below code on button click event:
pre
code
alert("Origin text: " + inputTextLocal);
inputTextLocal = inputTextLocal.substring(1,4);
alert("Substring: " + inputTextLocal);
/code
/pre


Beginner needs help using javascript to manipulate a string value

Posted: Sun Feb 16, 2014 3:28 pm
by Todd Penny6646042

I tried this and it did not work either. Just for context, I am able to create a test page that takes an input string, saves it to local storage then displays it when a button is pressed so I am confused as to why this simply string processing is not working as expected.


Beginner needs help using javascript to manipulate a string value

Posted: Sun Feb 16, 2014 3:28 pm
by Todd Penny6646042

BTW: Thanks for all your help - I appreciate it! Todd


Beginner needs help using javascript to manipulate a string value

Posted: Sun Feb 16, 2014 3:34 pm
by Igor

Could you clarify inputTextLocal is localStorage variable or JS variable?


Beginner needs help using javascript to manipulate a string value

Posted: Sun Feb 16, 2014 4:33 pm
by Todd Penny6646042

I create a localstorage variable when the button is clicked by binding the value to the input text field.


Beginner needs help using javascript to manipulate a string value

Posted: Sun Feb 16, 2014 4:40 pm
by Igor

Lets try below code on button click event:
pre
code
var inputText = localStorage.getItem("inputTextLocal");
alert("Local storage value: " + inputText);
var inputTextSubstring=inputText.substring(1,4);
alert("Substring: " + inputTextSubstring);
/code
/pre
where "inputTextLocal" - local storage variable name;


Beginner needs help using javascript to manipulate a string value

Posted: Sun Feb 16, 2014 8:01 pm
by Todd Penny6646042

This did not work either. I was able to get an alert to pop up, but there was no data displayed.