Page 1 of 1

call a javascript function in an event and use variables

Posted: Tue Sep 30, 2014 7:12 am
by arnaud charlier

Hi,

first, sorry if it's a dumb question, but I'm not really a dev so please help even if it's stupid :)

I created a function in a new JS file

function getVal(Val1, Val2) {

Code: Select all

 MyVal = Val1 * 360 / Val2 * 100; 
 return MyVal; 

}

I would like to call it from an event, but it doesn't seem to be working

On Keyup:
var Myval = getVal(Input1.val(), Input2.val());
alert (Myval);

Unfortunately, this doesn't seem to work, although I'm pretty sure that should work on a normal HTML page...
I would also like to be able to read and set variables defined on this JS page, is this possible ?

thanks for your help


call a javascript function in an event and use variables

Posted: Tue Sep 30, 2014 9:05 am
by Kateryna Grynko

Hi Arnaud,

Could you please clarify how you get Input1 and Input2?

Instead of codeInput1.val()/code or codeInput2.val()/code you should use:preAppery("inputname").val()/pre


call a javascript function in an event and use variables

Posted: Tue Sep 30, 2014 9:13 am
by arnaud charlier

I use
var Input1 = Appery("Input1");
var Input2 = Appery("Input2");

if I do
alert(Input1.val());
the expected value pops up.


call a javascript function in an event and use variables

Posted: Tue Sep 30, 2014 1:36 pm
by Kateryna Grynko

Hi Arnaud,

Could you please tell what happens when you run codealert(Input1.val());/code? Are there any errors in console?


call a javascript function in an event and use variables

Posted: Tue Sep 30, 2014 8:43 pm
by arnaud charlier

Hi Kat,

That's fine, it works now, thank you for your help, you pointed me to the right direction !

I tried to move var Input1 = Appery("Input1"); on the JS page to see if I could re-use the variable, but by the looks of it, the answer is no.

Which brings back to my second question:
I would also like to be able to read and set variables defined on this JS page, inside an event function.

Is this possible ?

Something down the line of

javascript1.js:

var a = 9;

-----

On Keyup:
var Myval = (a + a)

Thanks !


call a javascript function in an event and use variables

Posted: Thu Oct 02, 2014 8:41 pm
by Evgene Karachevtsev

Hi Arnaud,

You are asking about the scope of variables in js. Please look here:
https://developer.mozilla.org/en-US/d...
https://developer.mozilla.org/en-US/d...