0

I have some jquery script used to check password strength which changes an img src depending on complexity.

jsFiddle

Which works well within jsfiddle (set to jquery 1.91 - I know I need to get it updated at some point, but don't have time to go over the entire site right now) - on my webpage however, the event isn't being fired.

even going for something more simple:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
<script type="text/javascript">
    $('#txtNewPass').on('input', function () {
        alert('input');
    });
</script>
<input type="password" id="txtNewPass" runat="server" />

the alert doesn't popup.

I'm sure it is something silly I've overlooked, but I'd appreciate if someone could point it out.

Thanks

Kevin M
  • 442
  • 3
  • 11
  • 5
    Your website is simply missing `$(document).ready`, which jsFiddle adds for you automagically. – adeneo Aug 10 '16 at 18:53
  • 1
    As above: `$(function() { $('#txtNewPass').on('input', function () { alert('input'); }); };` will do it – StudioTime Aug 10 '16 at 18:54
  • Thanks - that was certainly part of it. But it was on my master page, so txtNewPass was actually coming up as ctl00_txtNewPass - so the event was never firing as the control id didn't exist. – Kevin M Aug 10 '16 at 19:46

3 Answers3

0

Give this a try:

$(function () {
    $('#txtNewPass').on('keypress', function () {
        alert($(this).val());
    });
});
-1

You might be looking for keydown/keyup

$( "#target" ).keydown(function() {
  alert( "Handler for .keydown() called." );
});
CasualBot
  • 86
  • 5
-1

I believe the correct event you're looking for is 'change', not 'input'.

$('#txtNewPass').on('change', function () {
    alert('input');
});

You can also use

$('#txtNewPass').change()

https://api.jquery.com/change/

Rupayan Neogy
  • 73
  • 1
  • 10