Solved

JavaScript or JQuery code for clicking a button?

  • 20 August 2018
  • 1 reply
  • 254 views

I know forms can do tabs at the top, but there seems to be no option for tabbing things in the middle of a view, so I made a tab menu through a data label.
However when I click one of the tabs I want it to click an invisible button (since I figured it would be easier than figuring out how to launch a rule directly)

These are the JS commands I have tested but the button is never clicked:

$( '[name="ButtonName'"] ').click();


document.getElementById("ButtonName").click();

 

var dsmButton = document.getElementById("ButtonName");

dsmButton.click();

 

Neither of those examples worked for clicking the button, and I am not sure why.
The html in the data label renders fine and just to test it I did a document.write("test");

and that worked, so I know the script is executing. Does anyone know how to trigger a button click through js?

icon

Best answer by Kran 21 August 2018, 08:57

View original

1 reply

Badge +9

Hi  Davidedpg,

 

Javascript and jquery commands you have used are not correct.

 

In Jquery one extra inverted coma  is used

 

 

$( '[name="ButtonName'"] ').click();
should be
$('[name="ButtonName"]').click();

  and in javascript  code you are trying to search button having name "ButtonName" using getelementbyId.

 

which means you are searching for element with ID "ButtonName" not for attribute name with value "ButtonName".

 

 

document.getElementById("ButtonName").click();

var dsmButton = document.getElementById("ButtonName");
dsmButton.click();

should be
document.getElementsByName("ButtonName")[0].click();

var dsmButton = document.getElementsByName("ButtonName")[0];
dsmButton.click();

Thanks,

Kran

Blog: k2recipes

 

Reply