1

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.net/yc6cq/


I just found the reason, it caused by jsfiddle!

enter image description here

Please note it will load mootools 1.4.5 on onLoad event. Everything will be OK if I set it as no wrap

Freewind
  • 193,756
  • 157
  • 432
  • 708
  • 2
    have you considered registering the event handler properly using `addEventListener()`? Would be much cleaner! – ThiefMaster Dec 13 '12 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 Dec 13 '12 at 13:02
  • You just create file in your local system and try – Miqdad Ali Dec 13 '12 at 13:07
  • Possible duplicate of [HTML form action and onsubmit issues](http://stackoverflow.com/questions/16262797/html-form-action-and-onsubmit-issues) – Suma Sep 27 '16 at 12:12

2 Answers2

4
<form onsubmit="return submitAdvice(this);">
    <input type="submit" value="submit" />
</form>​

function submitAdvice(f) {
    alert('submitting');
    return false;
}
Miqdad Ali
  • 6,129
  • 7
  • 31
  • 50
0

Try with this form statement

<form onsubmit=" return submitAdvice(this);">

http://jsfiddle.net/T3Qae/

Sovan
  • 104
  • 3