Freewind
Freewind

Reputation: 198178

`onsubmit` of html form doesn't work

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

Upvotes: 1

Views: 14296

Answers (2)

Sovan
Sovan

Reputation: 104

Try with this form statement

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

http://jsfiddle.net/T3Qae/

Upvotes: 0

Miqdad Ali
Miqdad Ali

Reputation: 6147

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

function submitAdvice(f) {
    alert('submitting');
    return false;
}

Upvotes: 4

Related Questions