1

I have some problems to run the following code, the js:

 $(document).ready(function(){
$.validator.addMethod("name", function(value, element) {
    return $("#identiPIC_selected_0").val() !== '' &&    $("#identiPIC_selected_1").val() !== '' ;
}, "Required!");

$("#signin").validate({
    groups:{
         name : 'identiPIC_selected[]'  
    },
    rules: {
        'identiPIC_selected[]': {
            required: true,
            remote: { 
                url:"check3.php",
                type:"post",
                cache: false,
                async:false,
                data: {
                    'identiPIC_selected[0]': function() {
                        return $.trim($("#identiPIC_selected_0").val());
                    },
                    'identiPIC_selected[1]': function() {
                        return $.trim($("#identiPIC_selected_1").val());
                    }
                }
            }
        }
    }
});

});

the php is the following:

<?php
 $captcha = $_POST['identiPIC_selected'];
$identiPIC[0] = "Apple";
$identiPIC[1] = "Flower";
 if($captcha === $identiPIC){
    echo "true";
 } else {
    echo "false";
 }

?>

and the html:

<form id="signin" action="check3.php" method="POST">
<select id="identiPIC_selected_0" name="identiPIC_selected[]">
<option value="">Click to identify</option>
<option>Apple</option>
<option>Cat</option>
<option>Clock</option>
<option>Flower</option>
<option>Fork</option>
</select>
<select id="identiPIC_selected_1" name="identiPIC_selected[]">
<option value="">Click to identify</option>
<option>Apple</option>
<option>Cat</option>
<option>Clock</option>
<option>Flower</option>
<option>Fork</option>
</select>
<input type="submit" id="save" name="save" value="Save"/>
</form>

This code works well when, except when the user selects the second "select" option wrong, presses submit and then fixes his mistake and then he presses submit it just doesnt submit anymore, so what i mean is for example:

User selects: Apple + Cat and click on save button, displays error, User fixes the problem: Apple + Flower and click on save button, it doesnt submit, even all the picks are good.

I added this :

$("#identiPIC_selected_0").change(function () {
    $("#identiPIC_selected_0").removeData("previousValue");
});
$("#identiPIC_selected_1").change(function () {
   $("#identiPIC_selected_1").removeData("previousValue");
});

but it doesnt seem to do anything for me. Anyone any ideas? Thanks!!!

4

1 回答 1

0

ok... after different tries i think i found the solution, this seems to work:

   $('#signin').submit(function(){
    $("#identiPIC_selected_0").removeData('previousValue');
    $("#identiPIC_selected_1").removeData('previousValue');
})
于 2012-10-02T11:13:58.813 回答