-1

Possible Duplicate:
jQuery Validation plugin - Validating hidden inputs and not visible?

I'm trying to validate a hidden text field for a specific word using equalTo, but it seems to be validating false. What's the right way to do this?

<input type="hidden" name="aImg" value="true" class="aImg">

$("#artcForm").validate({

        rules: {

            aImg: {
                required: true,
                equalTo: "true"
            },
        },  
Community
  • 1
  • 1
Norman
  • 6,159
  • 23
  • 88
  • 141

2 Answers2

1

Hey Norman see working sample here for you case Demo: http://jsfiddle.net/rgHkD/

So in equalTo attribute I am comparing the default value of hidden field - click on the "contibue step 2" for the validation.

Hope it fits the need! :)

code

   $('form').validate({
       ignore: "",
       rules: {
           first_nameo: {
                required: true,
                equalTo: "#FirstName"
            },
           first_name: {
                required: true
           },
            last_name: "required",
            address: "required"
        }
    });

image When you type false it will fail

enter image description here

Success when you type true in first name text box

enter image description here

Tats_innit
  • 33,991
  • 10
  • 71
  • 77
  • This is the way it is right now. We're using two hidden fields. So there's no way to make it look for a specific word without using two hidden fields? – Norman Oct 08 '12 at 08:42
  • AHa! Hiya @Norman there is a way see here: http://stackoverflow.com/questions/3571347/how-to-add-a-not-equal-to-rule-in-jquery-validation add the new method to your rules and then you can do whateven you feel like. `:)` hope this will help you! – Tats_innit Oct 08 '12 at 08:52
0

check this, you have to add another hidden field with you prerequested value:

<input name="h1" type="hidden" disabled="disabled" class="required" id="h1" value="your value"/>

<input name="h2" type="hidden" disabled="disabled" class="required"  equalTo="#h1" id="h2" value=""/>

jquery ref

hope it work:)

MMALSELEK
  • 777
  • 6
  • 13