Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1527 How do you submit a form by hitting return in a textarea?

You are here: irt.org | FAQ | JavaScript | Form | Q1527 [ previous next ]

This script monitors each key. When key char #13 is pressed, the form submits. Change the key char #, or replace the submit() for other functionality:

<script language="JavaScript"><!--
var isNav, isIE

if (parseInt(navigator.appVersion) >= 4) {
  if (navigator.appName == "Netscape")
    isNav = true
  else
    isIE = true
}

function showKeyValue(evt) {
  var keyValue

  if (isNav)
    keyValue = evt.which
  else
    keyValue = window.event.keyCode

  /*status = keyValue*/

  if (keyValue == 13) {
    /*alert(keyValue)*/
    javascript:document.search.submit();
  }
  return false
}
//--><script>

<form id="form1" name="search">
<textarea cols="30" rows="4" onKeyPress="showKeyValue(event)" wrap="virtual" id="textarea1" name="textarea1">
</textarea>
</form>
</body>
</html>

Submitted by Iain

©2018 Martin Webb