View Full Version : Can't get GM to click a button after filling form
SmileYaDead
10-04-2017, 05:26 AM
So I have this to fill a text field, but I can't get the script to click the button after the text is filled:
window.onload = function() {
document.forms['giveform'].elements['or_name'].value = "myvalue";
}
This works for another script:
document.getElementsByName('elementname')[0].click();
Oh, and if it could close the tab where the script was running, it would be awesome!
+rep for help :)
I remember two more ways to click a button besides the one you mentioned.
First is using jQuery
$('[name="elementname"]').click();
It doesnt always work on GM, but it should if you add this at the top:
[Only registered and activated users can see links]
Also looking for it by tags like this:
document.getElementsByClassName("classname")[0].getElementsByTagName("form")[0].getElementsByTagName("input")[0].click();
I dont know how to close a tab though, never done it before...
--
Oh, i just remembered another one, if the button is in a form, something like this should work:
document.forms.giveform.submit();
SmileYaDead
10-04-2017, 08:05 AM
I remember two more ways to click a button besides the one you mentioned.
First is using jQuery
$('[name="elementname"]').click();
It doesnt always work on GM, but it should if you add this at the top:
[Only registered and activated users can see links]
Also looking for it by tags like this:
document.getElementsByClassName("classname")[0].getElementsByTagName("form")[0].getElementsByTagName("input")[0].click();
I dont know how to close a tab though, never done it before...
--
Oh, i just remembered another one, if the button is in a form, something like this should work:
document.forms.giveform.submit();
The last one worked nicely, had to add a delay for it to not jump forward of the fill form part, but that's not a biggie :)
To close a tab you can use:
close();
or
window.close();
both are the same since window is implied.
SmileYaDead
10-04-2017, 05:01 PM
To close a tab you can use:
close();
or
window.close();
both are the same since window is implied.
Doesn't it only apply to windows/tabs generated by the script itself?
Doesn't it only apply to windows/tabs generated by the script itself?
I might be wrong but if I recall right each window(tab) have its own window object which is a global object that represents the window(tab) itself and all of them have the objects, functions and variables avaible automatically. Did u try it?
SmileYaDead
10-05-2017, 04:06 AM
I might be wrong but if I recall right each window(tab) have its own window object which is a global object that represents the window(tab) itself and all of them have the objects, functions and variables avaible automatically. Did u try it?
Ah, you were right, it worked indeed!
Powered by vBulletin® Version 4.2.0 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.