1

[UPDATED]

I'm using JQuery Validate plugin to validate a simple form. It's form HTML:

<form id="commentForm">
<div id="ContactUsDIV">
    <div id="right">
        <div class="ContactFormInput">Subject:</div>
        <input id="ContactFormSubject" name="ContactFormSubject" type="text" class="input"/>
        <label for="ContactFormSubject" class="validationMessage"></label>

        <div class="ContactFormInput">Full Name:</div>
        <input id="FullName" name="FullName" type="text" class="input"/>
        <label for="FullName" class="validationMessage"></label>

        <div class="ContactFormInput">EMail:</div>
        <input id="EmailAddress" name="EmailAddress" type="text" class="inputLTR"/>
        <label for="EmailAddress" class="validationMessage"></label>

        <div>
            <input id="SendMessage" type="submit" value="Send" class="ContactFormSubmit"/>
        </div>
    </div>
    <div id="left">
        <div class="ContactFormInput">Message:</div>
        <textarea id="UserComment" cols="20" rows="2"></textarea>
        <label for="UserComment" class="validationMessage"></label>
    </div>

</div>
</form>

Java Script:

<script type="text/javascript">
    $.validator.setDefaults({
        submitHandler: function () { alert("submitted!"); }
    });

    $().ready(function () {

        // validate signup form on keyup and submit
        $("#commentForm").validate({
            rules: {
                ContactFormSubject: "required",
                FullName: "required",
                username: "required",
                EmailAddress: {
                    required: true,
                    email: true
                },
                UserComment: "required"
            },
            messages: {
                ContactFormSubject: "blah blah",
                FullName: "blah blah",
                username: "blah blah",
                email: "blah blah",
                UserComment:"blah blah"
            }
        });

    });
</script>

But when I click Send button nothing happens.

Available here: http://tinkerbin.com/wRh09opb

0

3 Answers 3

5

Try this for correct email validation messages

<script type="text/javascript">
    $.validator.setDefaults({
        submitHandler: function () { alert("submitted!"); }
    });

    $(document).ready(function () {

        // validate signup form on keyup and submit
        $("#commentForm").validate({
            rules: {
                ContactFormSubject: "required",
                FullName: "required",
                username: "required",
                EmailAddress: {
                    required: true,
                    email: true
                },
                UserComment: "required"
            },
            messages: {
                ContactFormSubject: "blah blah",
                FullName: "blah blah",
                username: "blah blah",
                EmailAddress: {required:"blah blah", email:"blah blah"},
                UserComment:"blah blah"
            }
        });

    });
</script>
Sign up to request clarification or add additional context in comments.

Comments

1

Instead of ContactFormSubject: "required"

use like this

rules:

  ContactFormSubject: {
                required: true }

messages:

ContactFormSubject: { required : "Please fill the field" }

Sample:

$("#AdditionalDetailsForm").validate({
    rules: {
        ignore: ":not(:visible)",
        Account_Number: {
            required: true
        },
        BaseJurisdiction: {
            required: true
        }
    },
    messages: {
        Account_Number: {
            required: "<br/> Please enter the field"
        },
        BaseJurisdiction: {
            required: "<br/> Please enter the field"
        }
    }
});

1 Comment

if u r submitting the form using jquery like $('#formId').submit(); Use this if( $("#commentForm").valid()){ $('#formId').submit(); }
0

Try whith this Javascript:

<script type="text/javascript">
    $.validator.setDefaults({
        submitHandler: function () { alert("submitted!"); }
    });

    $.ready(function () {

        // validate signup form on keyup and submit
        $("#commentForm").validate({
            rules: {
                ContactFormSubject: "required",
                FullName: "required",
                username: "required",
                EmailAddress: {
                    required: true,
                    email: true
                },
                UserComment: "required"
            },
            messages: {
                ContactFormSubject: "blah blah",
                FullName: "blah blah",
                username: "blah blah",
                email: "blah blah",
                UserComment:"blah blah"
            }
        });

    });
</script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.