tag:blogger.com,1999:blog-33260599.post6782376423778260654..comments2024-03-29T02:30:53.584-07:00Comments on Imposterrific - a blog by Jeff Scudder: The joys of onKeyDownJeff Scudderhttp://www.blogger.com/profile/13002167096451875802noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-33260599.post-26295355807331796442009-11-10T07:09:20.972-08:002009-11-10T07:09:20.972-08:00Interesting. In some quick Google-ing after my co...Interesting. In some quick Google-ing after my comment I couldn't determine definitely if an onSubmit event would ever bubble up/down to the actual form element or if you could detect where the onSubmit actually started from.<br /><br />If you could, you check if the origin was your input and then consume just that one.<br /><br />Thanks for the reply.Benjamin P Leehttps://www.blogger.com/profile/15089639187841179363noreply@blogger.comtag:blogger.com,1999:blog-33260599.post-57175360964894852302009-11-09T22:23:35.000-08:002009-11-09T22:23:35.000-08:00Great questions Ben. You can indeed set the onSubm...Great questions Ben. You can indeed set the onSubmit for a form and if it returns false then the browser will not perform the form method-action. Here's a short example:<br /> <br /><form method="GET" action="/testtesttest" id="testform"><br /> <input type="text" id="textinput" name="myText"></input><br /> <input type="submit" value="submit" id="submitbutton"></input><br /></form><br /><script><br /> document.getElementById('testform').onsubmit = function() {alert('ok'); return false;}<br /></script><br />However, the default behavior for most browsers is that if you press enter in an text input box in the form, then it "presses" the submit button.<br /><br />Tabs do register a key down event, but if you want to prevent them from moving focus to the next input, then the event will need to be consumed.Jeff Scudderhttps://www.blogger.com/profile/13002167096451875802noreply@blogger.comtag:blogger.com,1999:blog-33260599.post-13684520938443021712009-11-04T17:29:07.941-08:002009-11-04T17:29:07.941-08:00Assuming under some situations you DO want your fo...Assuming under some situations you DO want your form to post (and have set it up accordingly), I wonder if you can bind to the onSubmit event of the form and detect if the submition was caused by an Enter press from your given input box, or some other fashion (Submit button, other input box enter, javascript event invocation, etc.)<br /><br />Also, I wonder if any browsers support a submit event coming out of an input box. If so, you could bind directly to that.<br /><br />In either case you would make your code a bit more obscure, but depending on your logic, save yourself the processing time of being invoked on each keypress.<br /><br />Also, does a TAB in or out result in a key[up|down|press] on the input box.<br /><br />Interesting post. Gotta love the wonderful world of cross-browser javascript.Benjamin P Leehttps://www.blogger.com/profile/15089639187841179363noreply@blogger.com