Reputation: 16845
I am having dynamic text box in my form . I like to validate using bassistance jquery plugin.
http://bassistance.de/jquery-plugins/jquery-plugin-validation/
My textbox name is in array formate setting[], how to represent rules and messages
<input type="text" name="setting[]">
my validation script is
<script type="text/javascript">
$("#freebidz_frm").validate({
rules: {
setting:{
required: true
}
},
messages: {
setting: '<br>'+"Please enter Default Font Style"+''
}});
</script>
But it's not working ... somebody help me ! Thanks in advance
Upvotes: 1
Views: 2569
Reputation: 896
Despite what others are saying, it's valid (and useful) to include square brackets in your input names (invalid for IDs, however). Most server-side languages will process these as an array, which can save you a lot of time when writing the processing.
As for your script, there are two points where it may be going wrong:
I've copied your code into a new HTML page and the validation script worked properly when I made these two adjustments. Just be sure to wrap 'setting[]' in quotes in both the 'rules' and 'messages' parts of the script.
Since you're creating arrays from your inputs, I'm assuming this isn't the only 'setting[]' in the form. If that's the case, you'll have to get a little fancier - creating class rules can help you validate a set of inputs based on a common class (http://docs.jquery.com/Plugins/Validation/Validator/addClassRules).
Upvotes: 2