0
<input class="item-quantities valid" data-bomid="1939" data-rid="2054" id="AddedItemIDs_1939_" name="AddedItemIDs[1939]" onkeypress="return isNumberKey(event)" type="text" value="7" aria-invalid="false">

Can't get this to work. What I've tried...

$('.item-quantities, .valid').change(function () {
            alert("we are here");
});

or...

$('.item-quantities.valid').change(function () {
            alert("we are here");
});

or...

$('.item-quantities').change(function () {
            alert("we are here");
});

... and a few other variations.

Can't seem to figure out how to trigger this event. I've been playing around with various variations of $('.item-quantities, .valid'), to no avail. What is the correct way to do this?

1
  • 1
    change event only fires when focus out from the field Commented Nov 22, 2016 at 4:07

3 Answers 3

1
<!DOCTYPE html>
<html>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
        <script>
        $( document ).ready(function() {
            $(".item-quantities").change(function () {
                        alert("we are here");
            });
        });

        </script>
    </head>
    <body>

        <input id="items" class="item-quantities valid" type="text">
    </body>
<html>

That will do the trick for classes

Sign up to request clarification or add additional context in comments.

5 Comments

Yeah, I should have said that this textbox is generated inside of a grid, so it's any one of many textboxes, and I won't know the actual id.
Is this a dot net app?
<!DOCTYPE html> <html> <head> <script src="ajax.googleapis.com/ajax/libs/jquery/3.1.0/…> <script> $( document ).ready(function() { $(".item-quantities").change(function () { alert("we are here"); }); }); </script> </head> <body> <input id="items" class="item-quantities valid" type="text"> </body> <html>
Always put all jQuery code within a script tag and wrap the within $( document ).read(function(){});
I already have it wrapped in document.ready. I posted a new thread with more details. stackoverflow.com/questions/40734094/…
0

Try this:

$('.item-quantities.valid').change(function () {
    alert("we are here");
});

But change event of text only fires on its focus lost, its better to use keypress or keydown

Working fiddle

2 Comments

The fiddle does indeed work. But this solution isn't working on my page. Hrmmm!!
It DOES work in the fiddle. But for some reason it doesn't work on my page.
0

You can use oninput and onkeypress event like this: Working fiddle

    $('.item-quantities, .valid').on('input',function(e){
         alert("we are here")
        });

$('.item-quantities, .valid').on('change keypress', function(e){
         alert("we are xfgdfgdgdfg")
        });

Or like this

<input class="item-quantities valid" type="text" onchange="yourFunction();"
onkeyup="this.onchange();" onpaste="this.onchange(); onkeypress=this.onchange()" oninput="this.onchange();"/>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.