mardi 2 septembre 2014

jQuery Validate and dynamic add rules using ajax remote issue. (possible var scope?)


Vote count:

0




I am having difficulty getting the following piece of code to work as expected:



var counter = 0;
$('#add_row').click(function(e) {

$('input[name="user_email[' + counter + ']"]').rules("add", {
required: true,
email: true,
remote: {
url: 'process.php',
type: 'post',
cache: false,
data: {
user_email: function(Counter) {
return $('input[name="user_email[' + counter + ']"]').val();
},
},
},
});

Counter++;
});


Below line returns undefined



return $('input[name="user_email[' + counter + ']"]').val();


While without the variable Counter it returns the value from the form input field as expected. But then it's no longer dynamic.


Eg.



return $('input[name="user_email[0]"]').val();


What is wrong with this code?



asked 17 secs ago

Jai

1






jQuery Validate and dynamic add rules using ajax remote issue. (possible var scope?)

Aucun commentaire:

Enregistrer un commentaire