Todd Penny6646042
Posts: 0
Joined: Fri Feb 07, 2014 10:52 pm

Beginner needs help using javascript to manipulate a string value

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!

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

Beginner needs help using javascript to manipulate a string value

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).

Todd Penny6646042
Posts: 0
Joined: Fri Feb 07, 2014 10:52 pm

Beginner needs help using javascript to manipulate a string value

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?

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

Beginner needs help using javascript to manipulate a string value

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

Todd Penny6646042
Posts: 0
Joined: Fri Feb 07, 2014 10:52 pm

Beginner needs help using javascript to manipulate a string value

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.

Todd Penny6646042
Posts: 0
Joined: Fri Feb 07, 2014 10:52 pm

Beginner needs help using javascript to manipulate a string value

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

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

Beginner needs help using javascript to manipulate a string value

Could you clarify inputTextLocal is localStorage variable or JS variable?

Todd Penny6646042
Posts: 0
Joined: Fri Feb 07, 2014 10:52 pm

Beginner needs help using javascript to manipulate a string value

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

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

Beginner needs help using javascript to manipulate a string value

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;

Todd Penny6646042
Posts: 0
Joined: Fri Feb 07, 2014 10:52 pm

Beginner needs help using javascript to manipulate a string value

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

Return to “Issues”