I have a form that I would like to be submitted when you click the tab button on your keyboard. I think I'm doing with my own code... How will I do this?
1 Answer
myElement.keydown = function (e) {
if (e.which === 9) myForm.submit();
};
9 is the tab character. I think this is x-browser compatible.
3 Comments
Keenan Thompson
myForm is the name of the form? And myElement is what?
maerics
You could also use "document.body" instead of "myElement".
Adam Bergmark
myElement is the element you want to want to bind the event to, you may or may not want to bind it to document (the entire page), you could bind it to just an input element by fetching it, such as
document.forms.myFormId.elements.myElementId.keydown = .... myForm is the form element, such as document.forms.myFormId