JavaScript Validation

by Matthew Ohlman <matthew(at)ohlman.com>

 Date:  Tue, 25 Jun 2002 23:05:16 -0500
 To:  hwg-basics(at)hwg.org
  todo: View Thread, Original
Hi list. I have another problem. I have written a JavaScript validator, but 
I can't seem to get it to work. I'm pretty sure it is just something 
simple, so if somebody could look it over and tell me if they see anything 
I would really appreciate it!! Here is the code:

-----------------
<.HTML><.HEAD>
<.script language="javascript">
<!--
  function validate()
{

var errmessage = "Please fill in the following fields:";

    if(document.contact.yourname.value=="")
       {
     errmessage = errmessage + "- Your Name";
   }
    if (document.contact.EmailAddress.value=="")
      {
     errmessage = errmessage + "- Email Address";
   }
     if(document.conatct.question.value=="")
     {
    errmessage = errmessage + "- Your Questoion";
   }
    if (errmessage == "Please fill in the following fields:")
  {
     document.form.submit();
  }
  else {
   alert(errmessage);
   return false;
           }
   }

// -->
<./SCRIPT>

<./HEAD>
<.BODY><.FORM name="contact" METHOD="post" ENCTYPE="TEXT/PLAIN">
<.input type="text" name="YourName" size="20"><.br>
Your email address:* (so we can get back to you)
<.input type="text" name="EmailAddress"size="20"><.br>
Your company's name:
<.input type="text" name="comapny" size="20"><.br>
Type your question here:*
<.textarea name="question" rows="3" cols="25"><./textarea><.br><.br>
<.input type="submit" name="submit" value="Submit" onClick="validate">
<.input type="reset" name="reset">
<./form><./body><./html>
-------------

I have also tried changing where I call the function (validate), from the 
submit button, to the form (using OnSubmit). Thanks again.

Matthew






| Matthew Ohlman
| Ohlman Pages
| http://www.ohlman.com/
"There's a difference between a philosophy and a bumper sticker. "
     Charles M. Schulz

HTML: hwg-basics mailing list archives, maintained by Webmasters @ IWA