Hi,

I'm trying to change a Web Screen Local Variable when executing Javascript.

What i want to do is, when i change an input or a list, Jscript runs and gives me an alert, like this:

SyntaxEditor Code Snippet

$(document).ready(function(){
    
  $("input").change(function(){
    alert("The text has been changed.");   
  });
  $("select").change(function(){
    alert("The text has been changed.");
  });
});

This is working, btw.

What i want to do now is, when this happens, i want to change a screen local variable to True.


Any ideas?

Thanks,

André

Hi André,

The common pattern for these situations is to have an hidden button in the page which you call with document.GetElementById(' + "MyButton.Id + " ').click(), then you bind that button to a server action that does whatever you want. 

If your variable needs to get some value from that Javascript then you create an input (also hidden) and bind it to the variable.

Regards,

Hi Andre,


You can add logic to click button in your jquery code and follow the steps given by Afonso. It will solve your problem.


Thanks,

Rajat Agrawal

Afonso Aguas wrote:

Hi André,

The common pattern for these situations is to have an hidden button in the page which you call with document.GetElementById(' + "MyButton.Id + " ').click(), then you bind that button to a server action that does whatever you want. 

If your variable needs to get some value from that Javascript then you create an input (also hidden) and bind it to the variable.

Regards,

What is wrong with my sintax? I've created a button with the name MyButton. If i click on it, the action runs, but if i change the input, it doesn't run (but gives me the alerts). Code below.


Thanks

SyntaxEditor Code Snippet

$(document).ready(function(){
    
  $("input").change(function(){
    alert("The text has been changed.")
    document.GetElementById("MyButton.Id").click();
  });
  $("select").change(function(){
    alert("The text has been changed.")
    document.GetElementById("MyButton.Id").click();
  });
  
});


Solution

I found the problem. I'm using version 11 and the name of the button just changes everytime i refresh the page. I don't know why this happens (found it when inspecting the button).


The solution i used was to create a new class in CSS just for that button and, inside JScript, i used: 

document.querySelector('.rateRecipe .btns-one-small').click();

Thanks guys and Merry Christmas,


André

Solution

André Portugal wrote:


SyntaxEditor Code Snippet

$(document).ready(function(){
    
  $("input").change(function(){
    alert("The text has been changed.")
    document.GetElementById("MyButton.Id").click();
  });
  $("select").change(function(){
    alert("The text has been changed.")
    document.GetElementById("MyButton.Id").click();
  });
  
});


Hi, even though your solution works, you should know that you can target ID's.

The platform generates Id's dinamically like you've discovered, so you can't write the Id in a string, instead you use the Id property that you can see in service studio like so:

You cannot however acess the Id's in the Web Screen JavaScript which I'm assuming you are since you have no double quotes on your code. You'd have to put it on an expression in the screen.