Home > DeveloperSection > Forums > .change event not work as dynamic as expected
Monaj Singh
Monaj Singh

Total Post:41

Points:287
Posted on    November-23-2014 10:05 PM

 JQuery JavaScript 
Ratings:


 1 Reply(s)
 500  View(s)
Rate this:

I'm new to javascript, I'm using jquery, this is my html with php code:

<form action="" method="POST" enctype="multipart/form-data">

    <h1>Quantity 1</h1>

    <input id="btn1" type="number" name="cantpag" value="<?php echo $cp; ?>">

 

    <h1>Quantity 2</h1>

    <input id="btn2" type="number" name="cantreinv" value="<?php echo $cr; ?>">

 

    <input type="submit">

</form>

Here is my JS:

<script>

$(document).ready(function(){

    $(document).on('change','#btn1',function(){

        alert('works');

    });

});</script>

When I change the value of "#btn1", nothing happens immediately, instead, I must press tab or somwhere else to have the alert show up. Is there any way for this to be instant, as in, just adding or removing a number from the input field triggers the alert?



Kamlakar Singh
Kamlakar Singh

Total Post:194

Points:1396
Posted on    November-24-2014 12:07 AM

$(document).ready(function(){

        $(document).on('input','#btn1',function(){

            alert('works');

        });

    });

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<form action="" method="POST" enctype="multipart/form-data">

    <h1>Quantity 1</h1>

    <input id="btn1" type="number" name="cantpag" value="<?php echo $cp; ?>">

 

    <h1>Quantity 2</h1>

    <input id="btn2" type="number" name="cantreinv" value="<?php echo $cr; ?>">

 

    <input type="submit">

</form>


Don't want to miss updates? Please click the below button!

Follow MindStick