The html code is simple:
<form onsubmit="submitAdvice(this);return false;">
<input type="submit" value="submit" />
</form>
And the javascript code:
function submitAdvice(f) {
alert('submitting');
}
But when I click the submit
button, it doesn't alert submitting
, instead, it submits the form.
I don't know where is wrong.
PS: the live demo: /
I just found the reason, it caused by jsfiddle!
Please note it will load mootools 1.4.5
on onLoad
event. Everything will be OK if I set it as no wrap
The html code is simple:
<form onsubmit="submitAdvice(this);return false;">
<input type="submit" value="submit" />
</form>
And the javascript code:
function submitAdvice(f) {
alert('submitting');
}
But when I click the submit
button, it doesn't alert submitting
, instead, it submits the form.
I don't know where is wrong.
PS: the live demo: http://jsfiddle/yc6cq/
I just found the reason, it caused by jsfiddle!
Please note it will load mootools 1.4.5
on onLoad
event. Everything will be OK if I set it as no wrap
-
2
have you considered registering the event handler properly using
addEventListener()
? Would be much cleaner! – ThiefMaster Commented Dec 13, 2012 at 12:59 -
1
I just found the problem is caused by jsfiddle. It uses
mootools
by default(on the left panel). Everything is well when I removed it. – Freewind Commented Dec 13, 2012 at 13:02 - You just create file in your local system and try – Miqdad Ali Commented Dec 13, 2012 at 13:07
- Possible duplicate of HTML form action and onsubmit issues – Suma Commented Sep 27, 2016 at 12:12
2 Answers
Reset to default 4<form onsubmit="return submitAdvice(this);">
<input type="submit" value="submit" />
</form>
function submitAdvice(f) {
alert('submitting');
return false;
}
Try with this form statement
<form onsubmit=" return submitAdvice(this);">
http://jsfiddle/T3Qae/