Reputation: 2123
I want to use variable for jquery validation equalTo method. But not working for jquery selector. How can I do this?
HTML
<form id="form" method="post">
<div>
<input type="password" name="pass1" id="passM" required />
</div>
<div>
<input type="password" name="pass2" id="passR" required />
</div>
<button type="submit">Submit</button>
</form>
JS
var form = $('#form'),
el1 = '#'+form.find('#passM').attr('id'),
el2 = form.find('#passR').attr('name');
form.validate({
rules: {
el2: {
equalTo: el1
}
}
})
Upvotes: 2
Views: 1686
Reputation: 645
Would this work?
var form = $('#form'),
el1 = '#'+form.find('#passM').attr('id'),
el2 = form.find('#passR').attr('name');
var r = {};
r[el2] = { equalTo: el1 };
form.validate({
rules: r
});
Upvotes: 2