jquery - focus form element on mouseup or click -


i'm trying focus form element on mouseup or click after form validation function has been called on mousedown. can't figure out how focus invalid form element on 1 click of submit button - validates form.

"#submit_button mousedown" : function(el, ev) {          if(!validateform()){             return;         } "validateform": function(){         if($('#firstname').val().length<1){             $('#firstname').next('label.error').remove();             $('#firstname').addclass('text-error');             $('#firstname').closest('div.control-group').children('label.control-label').addclass('label-error');             $('#firstname').after('<label class="error" data-i18n="account.field_required"></label>');              $('label.error').i18n();             return false;         } else {             return true;         } }  "#myform input blur": function(el, ev){                    var currentid = el[0].id;         var currentvalue = el.val();         $(el).next('label.error').remove();         if($(el).is('input')){ $(el).removeclass('text-error'); }         if($(el).is('select')){ $(el).removeclass('select-error'); }         $(el).closest('div.control-group').children('label.control-label').removeclass('label-error');         if(currentid=="firstname" || currentid=="lastname"){             if(currentvalue.length<1){                 $('#'+currentid).addclass('text-error');                 $('#'+currentid).closest('div.control-group').children('label.control-label').addclass('label-error');                 $('#'+currentid).after('<label class="error" data-i18n="account.field_required"></label>');                 $('label.error').i18n();         } else {             return;         } }  "#submit_button mouseup" : function(el, ev) {      steal.dev.log('mouseup called');     if(!validateform()){         steal.dev.log('account form invalid');         var fielderrors = ($('#myform input.text-error').length>0) ? $('#myform input.text-error') : $('#myform input.select-error');         $('#'+fielderrors[0].id).focus();         return;               } }, 

i don't know why invalid element not focused on mouseup unless clicked twice.

thanks,

j


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -