Victorgalaxy
Victorgalaxy

Reputation: 397

jQuery form Validation not working?

this is my code for the "contact us" web page. How come it doesn't work with the jquery validator plugin? Did i do something wrong? Please help. Thanks! The validator simply doesn't work. It allows submitting the form even I didn't fill out anything.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
      <script src="http://code.jquery.com/jquery-latest.js"></script>
      <script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js"></script>

      <script>
      $(document).ready(function(){
        $("#myform").validate();
      });
      </script>
    </head>

    <body bgcolor="#ffffff">
    <div id="contactuscontent">
      <form class="cmxform" id="myform" method="post" action="sendmail.php">
    Your Name: <br />
    <input type="text" name="visitor" size="35"   />
    <br />
    Your Email:<br />
    <input type="email" name="visitormail" size="35"  />
    <br /> <br />
    Subject:<br />
    <input type="text"  name="subject" size="35"  />
    <br /><br />
    Mail Message:
    <br />
    <textarea name="notes" rows="4" cols="40"  ></textarea>
    <br />
    <input type="submit" value="Send Mail" />
    <br />
    </form>
    </div>
    </body>
    </html>

Upvotes: 0

Views: 2211

Answers (3)

webpro
webpro

Reputation: 1

Well, jQuery is awesome. But you can do a JavaScript Form Validation without jQuery also. May refer to this JavaScript Form Validation Tutorial.

Upvotes: -1

mcgrailm
mcgrailm

Reputation: 17640

  <script>
  $(document).ready(function(){
    $("#myform").validate();
  });
  </script>
</head>

<body bgcolor="#ffffff">
<div id="contactuscontent">
  <form class="cmxform" id="myform" method="post" action="sendmail.php">
Your Name: <br />
<input type="text" name="visitor" class="required" size="35"   />
<br />
Your Email:<br />
<input type="email" name="visitormail" class="email required" size="35"  />
<br /> <br />
Subject:<br />
<input type="text"  name="subject" class="required" size="35"  />
<br /><br />
Mail Message:
<br />
<textarea name="notes" rows="4" cols="40" class="required" ></textarea>
<br />
<input type="submit" value="Send Mail" />
<br />
</form>
</div>
</body>
</html>

you just need to add classes that you want on each imput not gonna go into detail but you need to look at web standards for html forms and input as well as good formatting practices

Upvotes: 2

Edgar Villegas Alvarado
Edgar Villegas Alvarado

Reputation: 18344

Your code works fine, but you didn't put any validation rule, that's why it does nothing.

EDIT: At least, add a class="required" to your mandatory inputs.

Best Regards.

Upvotes: 5

Related Questions