1

I need to submit a form on a specific page, and it needs to click a radio button before it submits the form.

I got everything working, however when I let GreaseMonkey submit the form the page just returns a white page. As where if I would click Submit manually, it says 'Wait a second please..' and then goes on to another page.

If neccessary I can give you the URL of the form I am talking about.

This is the script I am using:

$(document).ready(function() {
    $("input[pmmethod=paypal]").click();
$(".submit-button").click();
});

3 Answers3

2

Sounds like a event handler is attached to the button, you could try to simulate a mouse click on it using native JavaScript instead of the jQuery method;

function simulateClick(node) {
    var ev = document.createEvent("MouseEvents");
    ev.initMouseEvent("click", true, false, self, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
    return node.dispatchEvent(ev);
}

$(document).ready(function() {
    $("input[pmmethod=paypal]").click();
simulateClick( $(".submit-button")[0] );
});
Paul S.
  • 64,864
  • 9
  • 122
  • 138
1

I know whay tou want...

I've altered the original script and now it will work!

http://userscripts.org/scripts/show/153026

Kelsey
  • 11
  • 1
0

To submit a form using JavaScript, use submit() like this:

$(document).ready(function() {
    $("input[pmmethod=paypal]").click();
    $("#orderform").submit();
});
Kenny Linsky
  • 1,726
  • 3
  • 17
  • 41
  • Thank you for your reply. When I try your code, it doesn't do anything. Like I said, it does submit the form however it just goes on to a white page instead of actually advancing. This is the submit button according to Firebug: `` – user1828398 Nov 16 '12 at 02:06
  • @user1828398 Please post a link to the form. But also, try: `document.getElementById("form-id").submit()` instead. Make sure to replace `form-id` with the actual id of the form element on the page. – Kenny Linsky Nov 16 '12 at 02:11
  • I actually think you need to be logged in in order to get to the form, sorry. How can I get the ID of the form element? – user1828398 Nov 16 '12 at 02:16
  • If you're using Firebug to inspect the elements, follow the HTML up to where the `
    ` begins. It should look something like `
    `.
    – Kenny Linsky Nov 16 '12 at 02:18
  • Alternatively, you can try and replace the `$(".submit-button").click();` in your original code with: `$(".submit-button").form.submit();` also try `$("#orderform").submit();` or `document.getElementById("orderform").submit();` – Kenny Linsky Nov 16 '12 at 02:19
  • I really appreciate your help. This is the ID: `form id="orderform"` – user1828398 Nov 16 '12 at 02:20