faqts : Computers : Programming : Languages : JavaScript

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

8 of 8 people (100%) answered Yes
Recently 8 of 8 people (100%) answered Yes

Entry

why ENTER KEY does not post a page when i querystring a page ...! but it works fine when i submit

Apr 7th, 2008 23:05
ha mo, Dave Clark, Ky Dang, SK RK,


Try to trap the enterKey (code=13) an call the submit for the form.   
(I have not tested this so let me know if it does not work for you.)
function enterKeyTrap()
{
  if (window.event.keyCode == 13)
  {
    document.myForm.submit();
  }
}
<form name="myForm" onkeyup="enterKeyTrap();">
  <input type="submit" value="Go" name="B1">
</form>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SK,
Note that the above code will not work in all browsers.  The following 
is a more cross-browser version:
function enterKeyTrap(e)
{
  if (e)
  {
    if (e.which == 13) document.myForm.submit();
  }
  else
  {
    if (window.event.keyCode == 13) document.myForm.submit();
  }
  return true;
}
<form name="myForm" onkeyup="return enterKeyTrap()">
  <input type="submit" value="Go" name="B1">
</form>
Note, also, that some browsers may not like the onkeyup event for the 
FORM tag.  All browsers, though, will accept the onkeyup event coded, 
for example, on each textbox.
Take care,
Dave Clark
www.DaveClarkConsulting.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com