JQuery does not get password field value

I searched a lot on stackoverflow and other sites and got a lot of solutions, but mine didn't resolve anything. That is why I am posting this. I have a password field on my web page that was created dynamically by click.And link. I want to get the value entered in this password field into a variable when it loses focus. To do this, I created a jQuery function similar to this one.

$('#parentdiv').on('focusout', '#passwordfield', function() { var pass1 = $('#passwordfield').val(); alert(pass1); alert("Hello"); }); 

Here the first warning command will be displayed in nothing, but the second warning will appear with "Hello". This means that when the password field loses focus, this function is executed without any problems, but the problem is that it does not receive the value of the password field.

Please help me solve this problem.

EDIT

This is my html

 <input type="password" size=20 id="passwordfield" /> 
+4
source share
2 answers

you can try the following:

HTML code:

 <form id='form'> <input type='password' class='required' /> </form> 

JavaScript:

 $('#form .required').focusout(function(){ var txt = $(this).val(); $('.required').after(txt); }); 

or you can check this code at http://jsfiddle.net/92y6b/

+5
source

My solution based on the above idea:

 <input type="password" class="form-control" name="password" /> <script> $('input[name=password]').keyup(function(){ var password = $(this).val(); }); </script> 
0
source

Source: https://habr.com/ru/post/1479847/


All Articles