admin管理员组文章数量:1242840
I have searched a lot in stackoverflow and other sites and got many solutions but nothing solved mine.That is why I am posting this.I have a password field in my web page, which was created dynamically on a link click.And I want to get the value typed in that password field into a variable when it loses focus.For that i created a jQuery function like this.
$('#parentdiv').on('focusout', '#passwordfield', function() {
var pass1 = $('#passwordfield').val();
alert(pass1);
alert("Hello");
});
Here the first alert mand will displayed with nothing, but the second alert e with "Hello". Which means, when the password field loses its focus this function executes without any problem, but the problem is, it is not getting the password field value.
Please help me to solve this problem.
EDIT
This is my html
<input type="password" size=20 id="passwordfield" />
I have searched a lot in stackoverflow and other sites and got many solutions but nothing solved mine.That is why I am posting this.I have a password field in my web page, which was created dynamically on a link click.And I want to get the value typed in that password field into a variable when it loses focus.For that i created a jQuery function like this.
$('#parentdiv').on('focusout', '#passwordfield', function() {
var pass1 = $('#passwordfield').val();
alert(pass1);
alert("Hello");
});
Here the first alert mand will displayed with nothing, but the second alert e with "Hello". Which means, when the password field loses its focus this function executes without any problem, but the problem is, it is not getting the password field value.
Please help me to solve this problem.
EDIT
This is my html
<input type="password" size=20 id="passwordfield" />
Share
Improve this question
edited May 9, 2013 at 4:15
user2356932
asked May 9, 2013 at 3:57
user2356932user2356932
971 gold badge1 silver badge6 bronze badges
18
-
2
It wouldn't fix your problem, but since the event is delegated to
#passwordfield
, just use$(this).val()
inside the handler instead of the way you currently are using.val()
– Ian Commented May 9, 2013 at 4:00 - 2 Works for me: jsfiddle/MDFY3 – David Tansey Commented May 9, 2013 at 4:01
-
1
Also, it works fine for me with either way of getting
.val()
- jsfiddle/eD8va – Ian Commented May 9, 2013 at 4:01 - Can you show your HTML? what browser are you running on? – Jaya Mayu Commented May 9, 2013 at 4:02
- Try to reproduce your issue on jsfiddle – palaѕн Commented May 9, 2013 at 4:03
3 Answers
Reset to default 5you can try this:
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/92y6b/
My solution based on above idea:
<input type="password" class="form-control" name="password" />
<script>
$('input[name=password]').keyup(function(){
var password = $(this).val();
});
</script>
keyup/focusout may fail when typing very fast, using copy/paste etc.
You may try this:
var x = document.getElementById("myPsw").value;
本文标签: javascriptjQuery not getting the password field valueStack Overflow
版权声明:本文标题:javascript - jQuery not getting the password field value - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740090611a2223969.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论