1

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

1 Answer 1

2

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:

  1. Make sure the validation script is wrapped in jQuery's $(document).ready(function(){ ... }); (I'm assuming you have it in your full script)
  2. In the case of any special characters, try wrapping the input name (including square brackets) in quotes.

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).

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.