Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

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

irt.org | Knowledge Base | JavaScript | Form | Q1527 [ previous next ]

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

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


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 6th July 2009. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2009 irt.org, All Rights Reserved.