faqts : Computers : Programming : Languages : JavaScript : Forms : TextAreas/TextFields

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

23 of 27 people (85%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

How can I get a form NOT to submit when users press return/enter while in a text field? (some users in Italy have this prob)

Mar 15th, 2001 11:23
Rich Puskarich, Richard Hawkes,


This should solve the problem:


var NS = (window.Event) ? 1 : 0;

function checkKey(e) {
  var code = (NS) ? e.which : event.keyCode;
  
  if (code == "13"){
	return false; }
}

document.onkeypress = checkKey;