Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery validate onchange

I'm using http://jqueryvalidation.org/ plugin.

It validate on key up but no on change. For example:

<input type="text" id="test1" value="" name="test1">
<input type="checkbox" id="test2" name="test2" value="1"> 

jQuery('#test2').change(function() {
jQuery('#test1').val('Test1'); });

if I'm validating, validate error at #test1 shows, but when i click checkbox, it's not hidding.

I can do it in this way:

jQuery('#test2').change(function() {
jQuery('#test1').val('Test1');
jQuery('#test1').valid(); });

it works, but how to implement onchange method in validation plugin, for automatic, every field onchange validation? Not only onkeyup, but also onchange?

like image 564
Snafu Avatar asked Sep 14 '26 11:09

Snafu


1 Answers

Start using 'input' event instead of 'change'.

jQuery('#test2').on('input', function() {
    // do your stuff 
});
like image 80
ArdaTahsinAyar Avatar answered Sep 16 '26 08:09

ArdaTahsinAyar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!