views:

39

answers:

1
+1  Q: 

jquery validation

Hi,

i am using jquery validation as follow

var validator=$("#myform")
    .validate({
        rules: {
                   field1: { required: true },
                   field2: { required: true },
                   field3: { required: true },
                   field4: { required: true }

            }
});

field1, field2 are in tab0 and field3,field4 in tab1

If i click in tab1 without fill field1, field2 and fill field3, field4 the validation is true.

I guess in this case field1,field2 are hidden because of tabs.

Here is my form

<form  id="myform"  enctype="multipart/form-data" method="post" action="myaction.php" >
    <div id="tabs">
        <ul>
            <li><a href="#tab-1">tab1</a></li>
            <li><a href="#tab-2">tab2</a></li>
        </ul>

    <div id="tab-1">  
        <input type="text" name="field1" id="field1" />     
        <input type="text" name="field2" id="field2" />     
    </div>

    <div id="tab-2">  
        <input type="text" name="field3" id="field3" />     
        <input type="text" name="field4" id="field4" />     
    </div>
    </div>

    <button type="submit" name="save">
                <img src="/admin/graphics/icons/disk.gif" alt=""/>Save
    </button>
    </form>

How can i solve this.Any suggestion is welcome

A: 

return false; if fields are not filled . if empty.

zod