258
Views
8
Comments
Solved
JavaScript Input Parameter of A Function

Hi everyone!

Would appreciate your help with the following:


I have a function defined in advanced propreties of a screen

function checkCountryName (name) {     

...

}

Then I call this function in Extended Properties  (onclick) of a button. I want to pass a variable from the screen to the function. How can I do it? 

Thank you

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Solution

Yeah, the on click action is called by the button's on click. So you probably need to have a hidden button that's clicked from the first button's on click, the first button doing the refresh and the hidden butten than calling the on click action (or your JavaScript).

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

You can do that by injecting into the call of the JavaScript inside the extended properties, the value of the variable. Something like:

"checkCountryName(" + myLocalVariable + ")"

There's one big caveat though, and that's that the expression is evaluated right after the Preperation has run, so if the variable must be dynamic (i.e. you change its value in your screen), you need to refresh the button after you change the value.

2022-05-29 13-15-09
Valentyna Boiko

Thank you, I refreshed the button in OnClick Action of this button, but I guess the Script runs even before the OnClick Action

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Solution

Yeah, the on click action is called by the button's on click. So you probably need to have a hidden button that's clicked from the first button's on click, the first button doing the refresh and the hidden butten than calling the on click action (or your JavaScript).

2022-05-29 13-15-09
Valentyna Boiko

Thank you, Kilian. I created two different buttons just to test it. One button does the refresh and the other is calling javascript. For some reason it didn't work either for me.

In Reactive it's so much easier...

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Wel, better find out the reason :). Check the console for errors, and debug to see that the buttons are called in the right sequence.

2022-05-29 13-15-09
Valentyna Boiko
2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

You're welcome, hope you can make it work.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.