jQuery 1.7.1
I have a portion of jQuery like,
- var val;
- $('.script_list').change(function () {
- val = $container.find('.script_list').val();
- if( (val < valbefore) || (valafter < val) ) {
- $('.update').addClass('disabled');
- $('.message').html('<div class="alert alert-error">'
- + '<a class="close" data-dismiss="alert">×</a>'
- + 'The start value must be between '
- + valbefore
- + ' and '
- + valafter
- + '</div>');
- } else {
- $('.update').removeClass('disabled');
- $('.message').html('');
- }
- });
The important point is the line 6, where 'update' button gets disabled. This button starts DB communication, so it is crucial to avoid a wrong input before being clicked.
This piece of code seems to work well, but in fact there is a critical drawback.
After changing the input value AND move the focus, it would certainly disable the button. But if the focus stays the same after changing the value, the button is still active. Hence, the update action can be achieved even if the value is wrong.
How can I change the timing of disabling action? In other words, I want the button disabled as soon as the value is changed a tiny bit.
thanks in advance.
soujiro0725