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?

3 of 6 people (50%) answered Yes
Recently 3 of 6 people (50%) answered Yes

Entry

Is it possbile to filter user input in text area to prevent or trap certain characters?

Aug 11th, 2006 15:20
David Alden, Javascript User,


<html>
<script type="text/javascript" language="javascript">
	function filterUserInput(event){
		// keyCode for the SHIFT key is 16, for ENTER key is 13
		// this function basically doesn't allow the ENTER key 
to be pressed inside the TextArea
		// thus filtering out a certain key
		if(event.keyCode==13){
			return false;
		}
	}
/*
// this function tells you what key you are pressing, uncomment to use
document.onkeydown = function (evt) {
    alert(evt.which);
    alert(evt.keyCode);
    alert(evt.charCode);
  }
*/
</script>
	<form name="thisForm">
		<textarea onkeydown="return filterUserInput(event)" 
name="thisTextarea"></textarea>
	</form>
</html>