Welcome! Log In Create A New Profile

Advanced

Passing a value to a JS code in a button

Posted by Gus 
Gus
Passing a value to a JS code in a button
October 16, 2021 03:15PM
Hello All:
I'm working on a Webdev 26 project and I have a HTML control with some JavaScript code embedded on it. I need to call a function to refresh values, for which I need to call a ctrl.refresh(value) to change the value in run time.
I created a button in browser code, and using JS code, I call the refresh function. The idea is to click the button to change those values. If I use a constant (refresh(20) ) it works fine. The issue I have is how to pass a value to that function. What would be the right approach here?

Thanks
Gus
Argus
Re: Passing a value to a JS code in a button
October 17, 2021 12:14AM
not sure I understand the question, but here goes:

All the wlanguage in BROWSER code is automatically translated in JS code for execution. THis means that from the browser code, you can also CALL ANY JS function that you stored anywhere directly by it's name, and pass it any parameter it is waiting for

So...
MyCaseSensitiveJSFunction(MyValue)
... is all you need to do
Re: Passing a value to a JS code in a button
October 20, 2021 05:45PM
Hi Gus,

You can create a browser code function and change it from WL to JS by clicking on the WL text in the left corner.
Then the code should look like
function MyWBproc(param)
{
   MyJSfunction(param);
}
Then you can call this function with parameter in your button code.

Best regards,
Piet
Re: Passing a value to a JS code in a button
October 21, 2021 10:44PM
Also worth mentioning if you have a function or object in JS that you want to access in WL code you can prefix the EXTERN keyword like so;

EXTERN window
EXTERN MyFunction

MyFunction("simple value") // Call a function that takes a simple value. It gets a bit tricky if the function takes objects.

// Access the DOM

EXTERN document

pclTitle is dynamic object = document.getElementById("tzA3");


// Since we declared the window we can touch just about anything.
window.console.log(pclTitle.innerHTML)

Sadly, I find it easier to simply learn the basics of JavaScript and switch over to JS to take advantage of that syntax which typically requires less effort after the initial learning phase is complete.

Cheers!
Ken
Gus
Re: Passing a value to a JS code in a button
November 02, 2021 05:04AM
Thank you, guys!
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: