I am trying to create an adhoc code that save me pressing a repetitive button on a webpage, I opened F12 developer and tried using getElementbyID(..).click(); however didn't quite work, this is part extract of the button, I wonder if someone can advise what code I can use to automatically submit the button? Any help will be greatly appreicated. Best regards, Jon
Asked
Active
Viewed 71 times
0
-
4Please visit the [help], take the tour to see what and [ask]. Do some research, search for related topics on SO; if you get stuck, post a [mcve] of your attempt, noting input and expected output. – mplungjan Jan 10 '19 at 14:10
-
[JavaScript is NOT JAVA](https://stackoverflow.com/questions/245062/whats-the-difference-between-javascript-and-java) – mplungjan Jan 10 '19 at 14:11
-
1`document.getElementById("existing_Unique_ID_of_a_button").click()` – mplungjan Jan 10 '19 at 14:12
-
you need to use jquery – HamzaNig Jan 10 '19 at 14:12
-
4@HamzaNig No he does not – mplungjan Jan 10 '19 at 14:12
-
@mplungjan yeah but jquery its better than solo javascript – HamzaNig Jan 10 '19 at 14:14
-
@mplungjan but your right even javascript it work – HamzaNig Jan 10 '19 at 14:15
-
1@HamzaNig Please don't be this guy: https://www.doxdesk.com/img/updates/20091116-so-large.gif – CodeF0x Jan 10 '19 at 14:40
-
@CodeF0x your right (i see your profile ) and i anderstand :) – HamzaNig Jan 10 '19 at 15:07
-
@HamzaNig Please don't get me wrong, jQuery may be cool (I'm not using it) and stuff, but for just one single task any framework would be too much. Have a great day :). – CodeF0x Jan 10 '19 at 15:08
1 Answers
1
what code I can use to automatically submit the button
If this is for a regular form post without AJAX then you can select the form then use submit()
.
E.g.
/*
* The variable myform is previously determined such as by `document.forms[0]`
* or a similar DOM selector method
*/
myform.submit();
If this is for a non-form button then use the click()
method as suggested in the comments above. However, be aware that for this method there would have to be an Event Listener attached for the button to do anything of value.

seantunwin
- 1,698
- 15
- 15