Text Links Ads : Marketing Tips Store : Search Engine Optimization Strategies
WebPosition Gold Pro : Domain Registration Bank : Optilink Software : GoDefy
Mike's Marketing Tools : Mike's Ecommerce Software : Text Links Guide
 
Web HTML-HTML.com
You are here: HTML Codes >> Forms >> <INPUT ...> >> <INPUT onKeyPress="...">

Canceling the Key Press

Before reading through this page, you might want to check out these solutions first:

If onKeyPress returns false, the event is cancelled and it's as if nothing is typed. For example, this code never allows you to type anything in the field.

this code produces this
<INPUT onKeyPress="return false">
type something:

notice that the attribute starts with the word "return" which means that the rest of the statement is returned to the field object, canceling or allowing the event. Of course, it usually doesn't make sense to just never allow any typing, so you'll usually want to test if something is true or false. For example, you can only type in these fields if the Engineering checkbox is checked:

<INPUT TYPE=CHECKBOX NAME="engr"> Engineering<BR>
College: <INPUT NAME="college" onKeyPress="return this.form.engr.checked"><BR>
Focus:   <INPUT NAME="focus"   onKeyPress="return this.form.engr.checked">

Which gives us this form:

Engineering
College:
Focus:
Sometimes you want to allow or cancel the event based on which key was pressed. We show how to check which key was pressed in the next page.

Checking Which Key Was Pressed >>>

Copyright © 2002-8 Art Dacor USA LLC. All Rights Reserved.
3727 West Magnolia Blvd #489, Burbank, CA, 91505, USA.
www.HTML-HTML.com