Results 1 to 7 of 7

Thread: Can't get GM to click a button after filling form

  1. #1
    SmileYaDead's Avatar
    Joined
    Feb 2012
    Posts
    3,611
    Userbars
    7
    Thanks
    835
    Thanked
    842/474
    DL/UL
    129/0
    Mentioned
    355 times
    Time Online
    89d 14h 56m
    Avg. Time Online
    30m

    Can't get GM to click a button after filling form

    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
    Last edited by SmileYaDead; 10-04-2017 at 05:35 AM.

  2. #2
    Nyu's Avatar
    Joined
    Jun 2016
    Posts
    603
    Pronouns
    She
    Userbars
    30
    Thanks
    756
    Thanked
    968/256
    DL/UL
    32/0
    Mentioned
    107 times
    Time Online
    61d 18h 44m
    Avg. Time Online
    31m
    I remember two more ways to click a button besides the one you mentioned.
    First is using jQuery
    Code:
    $('[name="elementname"]').click();
    It doesnt always work on GM, but it should if you add this at the top:
    Code:
    // @require       http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js
    Also looking for it by tags like this:
    Code:
    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:
    Code:
    document.forms.giveform.submit();

  3. The Following User Says Thank You to Nyu For This Useful Post:

    SmileYaDead (10-04-2017)

  4. #3
    SmileYaDead's Avatar
    Joined
    Feb 2012
    Posts
    3,611
    Userbars
    7
    Thanks
    835
    Thanked
    842/474
    DL/UL
    129/0
    Mentioned
    355 times
    Time Online
    89d 14h 56m
    Avg. Time Online
    30m
    Quote Originally Posted by Nyu View Post
    I remember two more ways to click a button besides the one you mentioned.
    First is using jQuery
    Code:
    $('[name="elementname"]').click();
    It doesnt always work on GM, but it should if you add this at the top:
    Code:
    // @require       http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js
    Also looking for it by tags like this:
    Code:
    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:
    Code:
    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

  5. #4
    npm's Avatar
    Joined
    Dec 2011
    Posts
    813
    Userbars
    15
    Thanks
    735
    Thanked
    564/219
    DL/UL
    84/3
    Mentioned
    109 times
    Time Online
    83d 21h 28m
    Avg. Time Online
    28m
    To close a tab you can use:

    close();
    or
    window.close();

    both are the same since window is implied.

  6. #5
    SmileYaDead's Avatar
    Joined
    Feb 2012
    Posts
    3,611
    Userbars
    7
    Thanks
    835
    Thanked
    842/474
    DL/UL
    129/0
    Mentioned
    355 times
    Time Online
    89d 14h 56m
    Avg. Time Online
    30m
    Quote Originally Posted by hectorvazc View Post
    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?

  7. #6
    npm's Avatar
    Joined
    Dec 2011
    Posts
    813
    Userbars
    15
    Thanks
    735
    Thanked
    564/219
    DL/UL
    84/3
    Mentioned
    109 times
    Time Online
    83d 21h 28m
    Avg. Time Online
    28m
    Quote Originally Posted by SmileYaDead View Post
    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?
    Last edited by npm; 10-04-2017 at 05:45 PM.

  8. The Following User Says Thank You to npm For This Useful Post:

    SmileYaDead (10-05-2017)

  9. #7
    SmileYaDead's Avatar
    Joined
    Feb 2012
    Posts
    3,611
    Userbars
    7
    Thanks
    835
    Thanked
    842/474
    DL/UL
    129/0
    Mentioned
    355 times
    Time Online
    89d 14h 56m
    Avg. Time Online
    30m
    Quote Originally Posted by hectorvazc View Post
    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!

  10. The Following User Says Thank You to SmileYaDead For This Useful Post:

    npm (10-06-2017)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •