...

View Full Version : jQuery: how to validate an input text before submit or change the cursor?



tirengarfio
11-22-2010, 10:31 PM
Hi,

using jQuery, how to validate a required input text before submitting or placing the cursor in another field?

I've tried this below but it doesn't work.



$(document).ready(function() {
$("#form").validate({
rules: {
name: "coche4[marca]",
required: true
}
},
messages: {
comment: "You must insert something."
}
});
});


Regards

SB65
11-23-2010, 02:20 PM
Looks like you've got an extra closing bracket in there:


$(document).ready(function() {
$("#form").validate({
rules: {
name: "coche4[marca]",
required: true
}
},
messages: {
comment: "You must insert something."
}
});
});

..although, I'm not quite sure your syntax is right anyway. If you have a form like this:


<form id="form" method="post" action="">
<input name="mynamefield" type="text"/>
<input name="comment" type="text"/>
<input type="submit" />

</form>

then to make both of these elements required and specify a message, you'd need something like this:


$(document).ready(function() {
$("#form").validate({
rules: {
mynamefield: {
//"coche4[marca]",
required: true
},
comment: "required"
},
messages: {
comment: "You must insert something."
}
});
});



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum