Page 1 of 2

Showing Javascript variable from html box in label

Posted: Tue Oct 21, 2014 1:55 pm
by David wyatt

Hi,

i have a javascript form running in a html window, i need to show one of the variables in a label in side my app. Does anyone know if this is possible?


Showing Javascript variable from html box in label

Posted: Tue Oct 21, 2014 6:07 pm
by Kateryna Grynko

Hi David,

If I understand you correctly, you want to take a value from some field of your form and inset in a Label component.

If you need to display a value on another app page, then I would recommend that you save a field value in a local storage variable and use it on another page to save in a Label.


Showing Javascript variable from html box in label

Posted: Tue Oct 21, 2014 6:32 pm
by David wyatt

sorry i wasnt very clear. in my html component i have javascript that creates a variable based on randomly generated number, i need this variable to be shown in a label and ideally in a input box too.


Showing Javascript variable from html box in label

Posted: Tue Oct 21, 2014 8:07 pm
by Kateryna Grynko

Hi David,

[quote:]i have javascript that creates a variable based on randomly generated number"[/quote]
So you have a JavaScript variable (not a localStorage variable) and you want to use its value in a Label and/or in an Input component on the same page, right?


Showing Javascript variable from html box in label

Posted: Tue Oct 21, 2014 8:28 pm
by David wyatt

Yes thats right.


Showing Javascript variable from html box in label

Posted: Wed Oct 22, 2014 3:40 am
by Yurii Orishchuk

Hi David.

At first you should create this variable in "window" context.
So to store this variable correctly you should use something like:

pre

window.someVariable = "somevalue";

/pre

Then you can use following code(for example in "page show" event handler) to set value stored in this JS variable(in window context) to some label component:

pre

//Where "labelComponentName" is your goal label component name.
Apperyio("labelComponentName").text(window.someVariable);

/pre

Regards.


Showing Javascript variable from html box in label

Posted: Wed Oct 22, 2014 8:23 am
by David wyatt

Hi,

ive tried

window.score = 2;
Apperyio('score_label').text(window.score);

in my page load with score_label the name of my label. I have also tried it with a inputbox name and neither work.

ive also tried

Apperyio('score_input').val('2')

and

Apperyio('score_label').text('2')

and nothing is working


Showing Javascript variable from html box in label

Posted: Wed Oct 22, 2014 11:28 am
by Evgene Karachevtsev

Hello David,

  1. Could you please clarify, do you try to change the text of the label on page show event?
  2. Can you get the item itself? What do you have in the console when running on the same
    preevent console.log( Apperyio('score_label') );/pre ?

Showing Javascript variable from html box in label

Posted: Wed Oct 22, 2014 11:47 am
by David wyatt

hi
thats right i want the text in a label or input to show the value 2. i think there is an issue with my appery dashboard, as none of my javascript commands are working (including test commands from tutorials) and even my buttons set to navigate to another page arnt working


Showing Javascript variable from html box in label

Posted: Wed Oct 22, 2014 12:09 pm
by Evgene Karachevtsev

David,

Could you please share your project with a href="mailto:support@appery.io" rel="nofollow"support@appery.io/a and tell us its name and steps to reproduce the issue? http://devcenter.appery.io/documentat...