Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to submit form through jQuery onblur

So I am trying to submit the form through jQuery onblur (i.e. As soon as the focus leaves the password field, form submits through jQuery). There are similar questions but it's not what I am looking for. I tried using the document.getElementById but it isn't working.

Any help is appreciated. Thanks in advance.

<script>
    $(function(){
       $("#pswd").blur({
          $("#myForm").submit(); 
       });

    });

</script>
like image 584
Neil Avatar asked Nov 24 '25 08:11

Neil


1 Answers

As @dvenkatsagar suggested, you have some syntax errors,

Live Preview: http://codepen.io/larryjoelane/pen/VedXqr

(function($){

       //I selected the body tag first because I do not know if you are creating
       //the pswd element dynamically
       $("body").on("blur","#pswd",function(e){


          $("#myForm").submit(); 


       });

      })(jQuery);

It is not necessary but I changed the way your closure was structured just in case you want to use other libraries in the future inside your closure besides jQuery.

like image 194
Larry Lane Avatar answered Nov 26 '25 21:11

Larry Lane



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!