Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript click a button by name from chrome console

Tags:

javascript

I'm trying to click programmatically a button from a web page using chrome console.

(UPDATED)The code of the button looks like this :

<FORM METHOD=GET ACTION="/xxx/yyy/kkk.jsp" >
    <INPUT type="hidden" name="page" value="721">
    <INPUT type="hidden" name="reqType" value="ReprintO">
    <INPUT type="hidden" name="title" value="Reprint Label">
    <INPUT type="hidden" name="system" value="reprint">
    <td align=right width=25%><input type=submit value='>' name=BTN_CHOICE5/>
    <td>&nbsp;&nbsp;Reprint Label
</form>

There are a couple more buttons on the page that have value= '>', so I guess I need to click it using name. I tried document.querySelector('input[name="BTN_CHOICE4"]').click(); and it didn't work. How do I click this button using JS?

like image 420
Mr.SrJenea Avatar asked Jun 06 '16 21:06

Mr.SrJenea


1 Answers

If you have ID attribute you can use

$('#btnId').click();

Or If you want to go by name, you can use

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

But it would be good if you use by Id not by name as if multiple controls have same name attribute and value, then all those controls click event will be invoked.

like image 59
Rakesh Nalumachu Avatar answered Sep 19 '22 15:09

Rakesh Nalumachu