简体   繁体   中英

jQuery Validation not showing message

I am new to using jQuery Validation and have not been able to get it to work. I am just trying to have a message pop out saying missing first name. Is there anything missing in this script?

 <!-- Validate -->
        <script type="text/javascript" src="jquery.validate.min.js"></script>


$(document).ready(function(){
    $("#form").validate({
        firstname_1: { required:true },
        //same for your other fields
    }, {
    messages: {
        firstname_1: "Missing first name",
    }
});

<cfform name="form" id="form" method="post">

    <cfoutput><input type="text" name="firstname_#Add#" id="firstname_#Add#" placeholder="First"  validateat="onSubmit" validate="noblanks" required="yes" message="Please enter owner #Peoplecount#'s first name." value="#session.checkout.info["firstname_" & Add]#"></cfoutput>

You have the arguments to .validate() wrong. It just takes a single options argument, and the validation rules go in that argument:

$("#form").validate({
    rules: {
        firstname_1: {
            required: true
        },
        // Same for other fields
    },
    messages: {
        firstname_1: "Missing first name",
        // Repeat for other fields
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM