0

I want to stimulate the effect of clicking on button (submit button) through javascript or jQuery in a form. I tried using .click() in jQuery but got no as such response.

In FireBug Events, I get the following events on the submit button of the form.

mouseup { return fn.apply(object, args); }

function () {
return fn.apply(object, args);
}

mousedown { return fn.apply(object, args); }

function () {
return fn.apply(object, args);
}

Well I don't know if this information was useful anyway because both mouseup and mousedown seem to be same here.

The source of submit button appears like:

<input type="submit" name="submit" id="submit" value="Submit" />

I have tried other methods to submit the form like .submit() but they did not work. I guess I am left over with stimulating click of button only.

Code:

$('#answer').val("chicago");

$(form).submit();

<form id="level" method="post"> 

<br/> 
<label for="answer">Answer:</label> 


<input type="text" name="answer" id="answer" /> 

<input type="submit" name="submit" id="submit" value="Submit" /> 


</form> 
1
  • 2
    I think you want to "simulate" the effect, rather than "stimulate" it. StackOverflow isn't that sort of site ;) Commented Jul 20, 2011 at 14:43

2 Answers 2

4

Since your <input> is named submit, form.submit refers to your DOM element rather than the built-in submit function.

Rename your <input> and form.submit() will work fine

Sign up to request clarification or add additional context in comments.

5 Comments

Well I can't, because it's an external form and I am using GreaseMonkey here.
Hmmm... Try document.createElement("form").submit.call(form)
Well, can you explain how it would fix? It did not b.t.w
This code calls the submit method from another <form> on your form. I don't know why it wouldn't work. Try setting the existing <input>'s name (although that may break the site, so you might want to set it back afterwards)
You can actually rename an input with GM. Something may break in the app, but maybe not. Just try it.
1
$(form).submit();

That should do it. http://api.jquery.com/submit/

Whoops, missed that you tried that already. Include you're actual javascript and the form element and I can maybe help you debug that.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.