SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jun 2010
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JQuery required fields validation plug in

    So I downloaded the jQuery library and the plug ins library and put this in the head of the html file-

    <script src="jquery-1.4.2.js"></script>
    <script type="text/javascript" src="jquery.validate.js"></script>
    jQuery.validator.setDefaults({
    debug: true,
    success: "valid"
    });;
    </script>

    <script>
    $(document).ready(function(){
    $("#myForm").validate({
    rules: {
    field: "required"
    }
    });
    });
    </script>


    This would be for the required fields validator.

    My form id is "myForm" and my fields are set up like this:

    <div><label for="first_name">First Name<span class="asterik">*</span></label>
    <input id="first_name" maxlength="40" name="first_name" size="20" type="text" tabindex="2" /></div>

    I changed the input name to "required" instead of "first_name" and it didn't work.
    I also changed the input id to "field" and that didn't work either.

    Am I just not doing this correctly?

  2. #2
    SitePoint Member
    Join Date
    Jun 2010
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually I got it to work by simply adding a class name to the input field. However, now the submit button doesn't work. Not only that but when the required field is not filled out and jquery highlights the field and pops up a message it throw off the css formatting of the entire form. Does anyone know why it does this?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •