Reputation: 5671
This should be trivial, but I am not getting it :\
HTML
<form id="myform" action="#">
<input type="submit" value="Submit" />
<a href="#" onclick="$('myform').submit()">Submit</a>
</form>
JS (Prototype)
$('myform').observe('submit', function(e) {
alert('submitted!');
e.stop();
});
Why the submit is only triggered with the submit via input? Shouldn't the submit event be triggered with $('myform').submit()
also?
JSFiddle: http://jsfiddle.net/d8BdM/
Upvotes: 3
Views: 5344
Reputation: 38092
Change your javascript code like this:
$('myform').onsubmit = function() {
alert('submitted!');
return false;
};
Upvotes: 2
Reputation: 12295
Change the form like this:
<form id="myform" action="">
<input type="submit" value="Submit" id="sub_but" />
<a href="#" onclick="$('sub_but').click();">Submit</a>
</form>
And keep the other code; i tested in your fiddle and works.
Saludos ;)
Upvotes: 2