faqts : Computers : Programming : Languages : JavaScript : Forms

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

108 of 148 people (73%) answered Yes
Recently 5 of 10 people (50%) answered Yes

Entry

When a form has a single input text field and several submit buttons, how can I set the default button when Enter is pressed?

Apr 20th, 2000 04:31
Martin Honnen, Anthony Howe,


You don't even need a submit button to get a single text field form 
submitted, thus there is no submit button associated with pressing 
enter. That is just another way of submitting a form. If you want to 
associate a submit button with the enter key use key event handling:
<FORM NAME="formName">
<INPUT TYPE="text" NAME="aField" VALUE="Kibology"
       ONKEYDOWN="if ((event.which && event.which == 13)
                      || (event.keyCode && event.keyCode == 13)) {
                    this.form.submit0.click();
                    return false;
                  }
                  else return true;"
>
<INPUT TYPE="submit" NAME="submit0" VALUE="Kibo">
<INPUT TYPE="submit" NAME="submit1" VALUE="Maho">
</FORM>