Web Hosting Directory | Web Hosting Resources | Webmaster Resources | Domain Tools | Search Engine Marketing | Forums
  Signup
Today: 1,220   Yesterday: 1,015   Max: 1,872   Total: 464,273   Current Users : 30 (Member 0) 
DOMAIN TOOLS

WEBMASTER TOOLS

RELATED ARTICLES

SUBMIT AN ARTICLE

Write for us and get publicity, link to your website, and best of all get paid. Please visit our writers page for details.


LINK TO US

Link to us and earn points for each visitor you bring to us. Please visit our link partner page for details.

 

Attribute for <INPUT ...>
onKeyPress = "script command(s)"

Usage Recommendation
use it, but don't rely on it

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

onKeyPress runs a JavaScript when the user presses a key. onKeyPress can be used to cancel the event so that the character is never entered in the field. onKeyPress also helps you to check which key was pressed, allowing for different actions based on different keys.

For our first example, this short form contains several radio buttons and a single text field. The text field is for the "Other" radio button. Typing data in the text field implies that the "Other" button should be checked, so we'll use onKeyPress to make it automatic. Using onKeyPress, when the user types something in the text field, the last option is automatically checked:

<FORM ACTION="../cgi-bin/mycgi.pl" METHOD=POST>
How did you hear about our company?<BR>
<INPUT TYPE=RADIO NAME="media" VALUE="internet">Internet<BR>
<INPUT TYPE=RADIO NAME="media" VALUE="newspaper">Newspaper<BR>
<INPUT TYPE=RADIO NAME="media" VALUE="tv">Television<BR>
<INPUT TYPE=RADIO NAME="media" VALUE="other">Other ...

<INPUT NAME="othermedia" onKeyPress="var m=this.form.media;m[m.length -1].checked=true"><BR>

<INPUT TYPE=SUBMIT VALUE="send it">
</FORM>

This gives us this form:

How did you hear about our company?
Internet
Newspaper
Television
Other ...
In the next page we discuss how to cancel the key press event.

Copyright 1997-2002 Idocs, Inc. Written by Miko Sullivan.

 
 
 
What is your major source of website traffic?
 
 
 
 
 
 

ADVERTISEMENT

 
Cheap Web HostingBudget Web HostingEcommerce Web Hosting
Link to UsLink ExchangeAdvertisePrivacy PolicyTerms Of ServiceAbout UsContact UsSitemap
Copyright © 2006 - 2008 Broadband Media, Inc. All rights reserved.