spacer
Yehuda Shiran January 24, 2000
Form Validation
Tips: January 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Google Chrome Playing Catch-Up on Extensions
Open Solutions Alliance Gets New Leadership
Red Hat Spacewalk Expands Linux Management
Suppose you have a Web site that solicits applicants to send their resume to you. But you really don't want to read thousands of high school kids' resumes. You want to check the age field before submitting it. Here's a form that let's you do that:

Your age:

Desired Job:

Resume:

Here is the code that generates the form above:
<HTML>
<HEAD>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
<!--
function valid(form) {
  var field = form.age;  
  var userAge = parseInt(field.value);   
  if (!userAge) {
    alert("You must indicate your age.");
    return false;
  } else if (userAge >= 18) {  
      alert("Thank your for your resume.");  
      return true;
    } else {
        alert("You are only " + userAge + ". Try again when you are 18."); 
        field.focus();
        field.select();
        return false;
      }
}
// -->
</SCRIPT>

<FORM METHOD="POST"
      ACTION="mailto:you@yourdomain.com"
      ENCTYPE="text/plain"
      onSubmit="return valid(this)">
Your age:<BR><INPUT TYPE="text" NAME="age" SIZE="2"><BR>
Desired Job:<BR><INPUT TYPE="text" NAME="job" SIZE="40"><BR>
Resume:<BR><TEXTAREA NAME="resume" COLS="40" ROWS="5"></TEXTAREA><BR>
<INPUT TYPE="submit" VALUE="Send Resume">
</FORM>
</BODY>
</HTML>


People who read this tip also read these tips:

Look for similar tips by subject:

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
MS Access and MySQL · Cisco AutoQoS: VoIP QoS for Mere Mortals · While VoIP Adoption Explodes in Enterprise, Carrier Spending Lags