arnaud charlier
Posts: 0
Joined: Tue Sep 30, 2014 7:12 am

call a javascript function in an event and use variables

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

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

call a javascript function in an event and use variables

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

arnaud charlier
Posts: 0
Joined: Tue Sep 30, 2014 7:12 am

call a javascript function in an event and use variables

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

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

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

call a javascript function in an event and use variables

Hi Arnaud,

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

arnaud charlier
Posts: 0
Joined: Tue Sep 30, 2014 7:12 am

call a javascript function in an event and use variables

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 !

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

call a javascript function in an event and use variables

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

Return to “Issues”