samedi 21 mars 2015

why does pressing enter inside a text box click the first button and submit the form

Open the javascript console, put your cursor in the text box, and press enter. Why is the function "baz" called? How should it be suppressed?





function foo() {
console.log('foo');
}
function bar() {
console.log('bar');
}
function baz() {
console.log('baz');
}
function blee() {
console.log('blee');
}



<form onsubmit="foo()" action="javascript:blee()">
<input type="text" />
<button onclick="baz()">baz</button>
<button onclick="bar()">bar</button>
<input type="submit" />
</form>



Aucun commentaire:

Enregistrer un commentaire