Jquery change textfield value and run function












0















I'm struggeling to get a function to run when a textfield is changed on a button click. So when clicking a plus/min button the text input is changed to a new value. However I want to run a function when textfield value is changed either by those buttons or by typing a value inside the textfield.



Manually typing is working but somehow the function won't run when using a button.



My html (there are multiple table cells like below):



<td class="amt">
<button class="pp_order_min" type="button"><i class="fa fa-minus"></i></button>
<input type="text" maxlength="4" class="pp_count" value="0" name="count[1]" min="0">
<button class="pp_order_plus" type="button"><i class="fa fa-plus"></i></button>
</td>


My JS:



$(function(){ 

$('.pp_order_min').bind("click", function(){
if($(this).next().val() !== '0') $(this).next().val(parseInt($(this).next().val()) - 1);
$(this).next().trigger('change') // next is the input field
});
$('.pp_order_plus').bind("click", function(){
if($(this).prev().val() !== '999') $(this).prev().val(parseInt($(this).prev().val()) + 1);
$(this).prev().trigger('change') // prev is the input field
});

$('.pp_count').each(function(){ // using each since there are more input fields like this
$(this).bind('input', function(){ // also tried 'on change' etc
var amt = $(this).val();
getNewAttributes(amt);
console.log(amt);
});
});

});


I thought that trigger a change event and the bind an input event would work. But that's not the case! I also tried litterally every on change event that I could think off.



I'm probably overlooking something dumb here! Any help greatly appreciated.










share|improve this question




















  • 1





    Why don't you trigger 'input'?

    – yunzen
    Nov 20 '18 at 13:02











  • @HerrSerker: Like I said I was missing something dumb :facepalm

    – Meules
    Nov 20 '18 at 13:05











  • BTW .bind() is deprecated as of jQuery 3. api.jquery.com/bind/#entry-longdesc You should use .on() instead api.jquery.com/on

    – yunzen
    Nov 20 '18 at 13:09













  • @HerrSerker: Yes you're right. I was mixing some old code with new code. Generally not the best idea in terms off making dumb mistakes like above :)

    – Meules
    Nov 20 '18 at 13:10
















0















I'm struggeling to get a function to run when a textfield is changed on a button click. So when clicking a plus/min button the text input is changed to a new value. However I want to run a function when textfield value is changed either by those buttons or by typing a value inside the textfield.



Manually typing is working but somehow the function won't run when using a button.



My html (there are multiple table cells like below):



<td class="amt">
<button class="pp_order_min" type="button"><i class="fa fa-minus"></i></button>
<input type="text" maxlength="4" class="pp_count" value="0" name="count[1]" min="0">
<button class="pp_order_plus" type="button"><i class="fa fa-plus"></i></button>
</td>


My JS:



$(function(){ 

$('.pp_order_min').bind("click", function(){
if($(this).next().val() !== '0') $(this).next().val(parseInt($(this).next().val()) - 1);
$(this).next().trigger('change') // next is the input field
});
$('.pp_order_plus').bind("click", function(){
if($(this).prev().val() !== '999') $(this).prev().val(parseInt($(this).prev().val()) + 1);
$(this).prev().trigger('change') // prev is the input field
});

$('.pp_count').each(function(){ // using each since there are more input fields like this
$(this).bind('input', function(){ // also tried 'on change' etc
var amt = $(this).val();
getNewAttributes(amt);
console.log(amt);
});
});

});


I thought that trigger a change event and the bind an input event would work. But that's not the case! I also tried litterally every on change event that I could think off.



I'm probably overlooking something dumb here! Any help greatly appreciated.










share|improve this question




















  • 1





    Why don't you trigger 'input'?

    – yunzen
    Nov 20 '18 at 13:02











  • @HerrSerker: Like I said I was missing something dumb :facepalm

    – Meules
    Nov 20 '18 at 13:05











  • BTW .bind() is deprecated as of jQuery 3. api.jquery.com/bind/#entry-longdesc You should use .on() instead api.jquery.com/on

    – yunzen
    Nov 20 '18 at 13:09













  • @HerrSerker: Yes you're right. I was mixing some old code with new code. Generally not the best idea in terms off making dumb mistakes like above :)

    – Meules
    Nov 20 '18 at 13:10














0












0








0








I'm struggeling to get a function to run when a textfield is changed on a button click. So when clicking a plus/min button the text input is changed to a new value. However I want to run a function when textfield value is changed either by those buttons or by typing a value inside the textfield.



Manually typing is working but somehow the function won't run when using a button.



My html (there are multiple table cells like below):



<td class="amt">
<button class="pp_order_min" type="button"><i class="fa fa-minus"></i></button>
<input type="text" maxlength="4" class="pp_count" value="0" name="count[1]" min="0">
<button class="pp_order_plus" type="button"><i class="fa fa-plus"></i></button>
</td>


My JS:



$(function(){ 

$('.pp_order_min').bind("click", function(){
if($(this).next().val() !== '0') $(this).next().val(parseInt($(this).next().val()) - 1);
$(this).next().trigger('change') // next is the input field
});
$('.pp_order_plus').bind("click", function(){
if($(this).prev().val() !== '999') $(this).prev().val(parseInt($(this).prev().val()) + 1);
$(this).prev().trigger('change') // prev is the input field
});

$('.pp_count').each(function(){ // using each since there are more input fields like this
$(this).bind('input', function(){ // also tried 'on change' etc
var amt = $(this).val();
getNewAttributes(amt);
console.log(amt);
});
});

});


I thought that trigger a change event and the bind an input event would work. But that's not the case! I also tried litterally every on change event that I could think off.



I'm probably overlooking something dumb here! Any help greatly appreciated.










share|improve this question
















I'm struggeling to get a function to run when a textfield is changed on a button click. So when clicking a plus/min button the text input is changed to a new value. However I want to run a function when textfield value is changed either by those buttons or by typing a value inside the textfield.



Manually typing is working but somehow the function won't run when using a button.



My html (there are multiple table cells like below):



<td class="amt">
<button class="pp_order_min" type="button"><i class="fa fa-minus"></i></button>
<input type="text" maxlength="4" class="pp_count" value="0" name="count[1]" min="0">
<button class="pp_order_plus" type="button"><i class="fa fa-plus"></i></button>
</td>


My JS:



$(function(){ 

$('.pp_order_min').bind("click", function(){
if($(this).next().val() !== '0') $(this).next().val(parseInt($(this).next().val()) - 1);
$(this).next().trigger('change') // next is the input field
});
$('.pp_order_plus').bind("click", function(){
if($(this).prev().val() !== '999') $(this).prev().val(parseInt($(this).prev().val()) + 1);
$(this).prev().trigger('change') // prev is the input field
});

$('.pp_count').each(function(){ // using each since there are more input fields like this
$(this).bind('input', function(){ // also tried 'on change' etc
var amt = $(this).val();
getNewAttributes(amt);
console.log(amt);
});
});

});


I thought that trigger a change event and the bind an input event would work. But that's not the case! I also tried litterally every on change event that I could think off.



I'm probably overlooking something dumb here! Any help greatly appreciated.







javascript jquery input onchange






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 12:59









Itay Gal

7,81152560




7,81152560










asked Nov 20 '18 at 12:53









MeulesMeules

67331341




67331341








  • 1





    Why don't you trigger 'input'?

    – yunzen
    Nov 20 '18 at 13:02











  • @HerrSerker: Like I said I was missing something dumb :facepalm

    – Meules
    Nov 20 '18 at 13:05











  • BTW .bind() is deprecated as of jQuery 3. api.jquery.com/bind/#entry-longdesc You should use .on() instead api.jquery.com/on

    – yunzen
    Nov 20 '18 at 13:09













  • @HerrSerker: Yes you're right. I was mixing some old code with new code. Generally not the best idea in terms off making dumb mistakes like above :)

    – Meules
    Nov 20 '18 at 13:10














  • 1





    Why don't you trigger 'input'?

    – yunzen
    Nov 20 '18 at 13:02











  • @HerrSerker: Like I said I was missing something dumb :facepalm

    – Meules
    Nov 20 '18 at 13:05











  • BTW .bind() is deprecated as of jQuery 3. api.jquery.com/bind/#entry-longdesc You should use .on() instead api.jquery.com/on

    – yunzen
    Nov 20 '18 at 13:09













  • @HerrSerker: Yes you're right. I was mixing some old code with new code. Generally not the best idea in terms off making dumb mistakes like above :)

    – Meules
    Nov 20 '18 at 13:10








1




1





Why don't you trigger 'input'?

– yunzen
Nov 20 '18 at 13:02





Why don't you trigger 'input'?

– yunzen
Nov 20 '18 at 13:02













@HerrSerker: Like I said I was missing something dumb :facepalm

– Meules
Nov 20 '18 at 13:05





@HerrSerker: Like I said I was missing something dumb :facepalm

– Meules
Nov 20 '18 at 13:05













BTW .bind() is deprecated as of jQuery 3. api.jquery.com/bind/#entry-longdesc You should use .on() instead api.jquery.com/on

– yunzen
Nov 20 '18 at 13:09







BTW .bind() is deprecated as of jQuery 3. api.jquery.com/bind/#entry-longdesc You should use .on() instead api.jquery.com/on

– yunzen
Nov 20 '18 at 13:09















@HerrSerker: Yes you're right. I was mixing some old code with new code. Generally not the best idea in terms off making dumb mistakes like above :)

– Meules
Nov 20 '18 at 13:10





@HerrSerker: Yes you're right. I was mixing some old code with new code. Generally not the best idea in terms off making dumb mistakes like above :)

– Meules
Nov 20 '18 at 13:10












3 Answers
3






active

oldest

votes


















0














You should trigger input instead of change, since this is what you are binding to.






share|improve this answer































    0














    use .change() instead trigger






    $(function(){ 

    $('.pp_order_min').bind("click", function(){
    if($(this).next().val() !== '0') $(this).next().val(parseInt($(this).next().val()) - 1);
    $(this).next().change() // next is the input field
    });
    $('.pp_order_plus').bind("click", function(){
    if($(this).prev().val() !== '999') $(this).prev().val(parseInt($(this).prev().val()) + 1);
    $(this).prev().change() // prev is the input field
    });

    $('.pp_count').each(function(){ // using each since there are more input fields like this
    $(this).bind('change input', function(){ // also tried 'on change' etc
    var amt = $(this).val();
    //getNewAttributes(amt)
    console.log(amt)
    });
    });

    });

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <td class="amt">
    <button class="pp_order_min" type="button"><i class="fa fa-minus"></i>-</button>
    <input type="text" maxlength="4" class="pp_count" value="0" name="count[1]" min="0">
    <button class="pp_order_plus" type="button"><i class="fa fa-plus"></i>+</button>
    </td>








    share|improve this answer































      0














      I suggest you to bind only one time change function to input box.






      $(function(){ 

      $('.pp_order_min').on("click", function(){
      var currentObj=$(this);
      debugger;
      if(currentObj.next().val() === '') return;
      if(currentObj.next().val() !== '0') currentObj.next().val(parseInt(currentObj.next().val()) - 1);
      currentObj.next().change(); // next is the input field
      });
      $('.pp_order_plus').on("click", function(){
      var currentObj=$(this);
      debugger;
      if(currentObj.prev().val() === '') return;
      if(currentObj.prev().val() !== '999') currentObj.prev().val(parseInt(currentObj.prev().val()) + 1);
      currentObj.prev().change(); // prev is the input field
      });
      $('.pp_count').on('change input', function(){ // also tried 'on change' etc
      var amt = $(this).val();
      console.log(amt)
      });
      $('.pp_count').each(function(){ // using each since there are more input fields like this
      $(this).click();//
      });
      });

      <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
      <td class="amt">
      <button class="pp_order_min" type="button"><i class="fa fa-minus"></i>-</button>
      <input type="text" maxlength="4" class="pp_count" value="0" name="count[1]" min="0">
      <button class="pp_order_plus" type="button"><i class="fa fa-plus"></i>+</button>
      </td>





      Please take a look here for multiple textbox.






      share|improve this answer























        Your Answer






        StackExchange.ifUsing("editor", function () {
        StackExchange.using("externalEditor", function () {
        StackExchange.using("snippets", function () {
        StackExchange.snippets.init();
        });
        });
        }, "code-snippets");

        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "1"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53393445%2fjquery-change-textfield-value-and-run-function%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        0














        You should trigger input instead of change, since this is what you are binding to.






        share|improve this answer




























          0














          You should trigger input instead of change, since this is what you are binding to.






          share|improve this answer


























            0












            0








            0







            You should trigger input instead of change, since this is what you are binding to.






            share|improve this answer













            You should trigger input instead of change, since this is what you are binding to.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 20 '18 at 13:07









            yunzenyunzen

            20.2k84779




            20.2k84779

























                0














                use .change() instead trigger






                $(function(){ 

                $('.pp_order_min').bind("click", function(){
                if($(this).next().val() !== '0') $(this).next().val(parseInt($(this).next().val()) - 1);
                $(this).next().change() // next is the input field
                });
                $('.pp_order_plus').bind("click", function(){
                if($(this).prev().val() !== '999') $(this).prev().val(parseInt($(this).prev().val()) + 1);
                $(this).prev().change() // prev is the input field
                });

                $('.pp_count').each(function(){ // using each since there are more input fields like this
                $(this).bind('change input', function(){ // also tried 'on change' etc
                var amt = $(this).val();
                //getNewAttributes(amt)
                console.log(amt)
                });
                });

                });

                <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
                <td class="amt">
                <button class="pp_order_min" type="button"><i class="fa fa-minus"></i>-</button>
                <input type="text" maxlength="4" class="pp_count" value="0" name="count[1]" min="0">
                <button class="pp_order_plus" type="button"><i class="fa fa-plus"></i>+</button>
                </td>








                share|improve this answer




























                  0














                  use .change() instead trigger






                  $(function(){ 

                  $('.pp_order_min').bind("click", function(){
                  if($(this).next().val() !== '0') $(this).next().val(parseInt($(this).next().val()) - 1);
                  $(this).next().change() // next is the input field
                  });
                  $('.pp_order_plus').bind("click", function(){
                  if($(this).prev().val() !== '999') $(this).prev().val(parseInt($(this).prev().val()) + 1);
                  $(this).prev().change() // prev is the input field
                  });

                  $('.pp_count').each(function(){ // using each since there are more input fields like this
                  $(this).bind('change input', function(){ // also tried 'on change' etc
                  var amt = $(this).val();
                  //getNewAttributes(amt)
                  console.log(amt)
                  });
                  });

                  });

                  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
                  <td class="amt">
                  <button class="pp_order_min" type="button"><i class="fa fa-minus"></i>-</button>
                  <input type="text" maxlength="4" class="pp_count" value="0" name="count[1]" min="0">
                  <button class="pp_order_plus" type="button"><i class="fa fa-plus"></i>+</button>
                  </td>








                  share|improve this answer


























                    0












                    0








                    0







                    use .change() instead trigger






                    $(function(){ 

                    $('.pp_order_min').bind("click", function(){
                    if($(this).next().val() !== '0') $(this).next().val(parseInt($(this).next().val()) - 1);
                    $(this).next().change() // next is the input field
                    });
                    $('.pp_order_plus').bind("click", function(){
                    if($(this).prev().val() !== '999') $(this).prev().val(parseInt($(this).prev().val()) + 1);
                    $(this).prev().change() // prev is the input field
                    });

                    $('.pp_count').each(function(){ // using each since there are more input fields like this
                    $(this).bind('change input', function(){ // also tried 'on change' etc
                    var amt = $(this).val();
                    //getNewAttributes(amt)
                    console.log(amt)
                    });
                    });

                    });

                    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
                    <td class="amt">
                    <button class="pp_order_min" type="button"><i class="fa fa-minus"></i>-</button>
                    <input type="text" maxlength="4" class="pp_count" value="0" name="count[1]" min="0">
                    <button class="pp_order_plus" type="button"><i class="fa fa-plus"></i>+</button>
                    </td>








                    share|improve this answer













                    use .change() instead trigger






                    $(function(){ 

                    $('.pp_order_min').bind("click", function(){
                    if($(this).next().val() !== '0') $(this).next().val(parseInt($(this).next().val()) - 1);
                    $(this).next().change() // next is the input field
                    });
                    $('.pp_order_plus').bind("click", function(){
                    if($(this).prev().val() !== '999') $(this).prev().val(parseInt($(this).prev().val()) + 1);
                    $(this).prev().change() // prev is the input field
                    });

                    $('.pp_count').each(function(){ // using each since there are more input fields like this
                    $(this).bind('change input', function(){ // also tried 'on change' etc
                    var amt = $(this).val();
                    //getNewAttributes(amt)
                    console.log(amt)
                    });
                    });

                    });

                    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
                    <td class="amt">
                    <button class="pp_order_min" type="button"><i class="fa fa-minus"></i>-</button>
                    <input type="text" maxlength="4" class="pp_count" value="0" name="count[1]" min="0">
                    <button class="pp_order_plus" type="button"><i class="fa fa-plus"></i>+</button>
                    </td>








                    $(function(){ 

                    $('.pp_order_min').bind("click", function(){
                    if($(this).next().val() !== '0') $(this).next().val(parseInt($(this).next().val()) - 1);
                    $(this).next().change() // next is the input field
                    });
                    $('.pp_order_plus').bind("click", function(){
                    if($(this).prev().val() !== '999') $(this).prev().val(parseInt($(this).prev().val()) + 1);
                    $(this).prev().change() // prev is the input field
                    });

                    $('.pp_count').each(function(){ // using each since there are more input fields like this
                    $(this).bind('change input', function(){ // also tried 'on change' etc
                    var amt = $(this).val();
                    //getNewAttributes(amt)
                    console.log(amt)
                    });
                    });

                    });

                    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
                    <td class="amt">
                    <button class="pp_order_min" type="button"><i class="fa fa-minus"></i>-</button>
                    <input type="text" maxlength="4" class="pp_count" value="0" name="count[1]" min="0">
                    <button class="pp_order_plus" type="button"><i class="fa fa-plus"></i>+</button>
                    </td>





                    $(function(){ 

                    $('.pp_order_min').bind("click", function(){
                    if($(this).next().val() !== '0') $(this).next().val(parseInt($(this).next().val()) - 1);
                    $(this).next().change() // next is the input field
                    });
                    $('.pp_order_plus').bind("click", function(){
                    if($(this).prev().val() !== '999') $(this).prev().val(parseInt($(this).prev().val()) + 1);
                    $(this).prev().change() // prev is the input field
                    });

                    $('.pp_count').each(function(){ // using each since there are more input fields like this
                    $(this).bind('change input', function(){ // also tried 'on change' etc
                    var amt = $(this).val();
                    //getNewAttributes(amt)
                    console.log(amt)
                    });
                    });

                    });

                    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
                    <td class="amt">
                    <button class="pp_order_min" type="button"><i class="fa fa-minus"></i>-</button>
                    <input type="text" maxlength="4" class="pp_count" value="0" name="count[1]" min="0">
                    <button class="pp_order_plus" type="button"><i class="fa fa-plus"></i>+</button>
                    </td>






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 20 '18 at 13:01









                    Luis felipe De jesus MunozLuis felipe De jesus Munoz

                    4,3901830




                    4,3901830























                        0














                        I suggest you to bind only one time change function to input box.






                        $(function(){ 

                        $('.pp_order_min').on("click", function(){
                        var currentObj=$(this);
                        debugger;
                        if(currentObj.next().val() === '') return;
                        if(currentObj.next().val() !== '0') currentObj.next().val(parseInt(currentObj.next().val()) - 1);
                        currentObj.next().change(); // next is the input field
                        });
                        $('.pp_order_plus').on("click", function(){
                        var currentObj=$(this);
                        debugger;
                        if(currentObj.prev().val() === '') return;
                        if(currentObj.prev().val() !== '999') currentObj.prev().val(parseInt(currentObj.prev().val()) + 1);
                        currentObj.prev().change(); // prev is the input field
                        });
                        $('.pp_count').on('change input', function(){ // also tried 'on change' etc
                        var amt = $(this).val();
                        console.log(amt)
                        });
                        $('.pp_count').each(function(){ // using each since there are more input fields like this
                        $(this).click();//
                        });
                        });

                        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
                        <td class="amt">
                        <button class="pp_order_min" type="button"><i class="fa fa-minus"></i>-</button>
                        <input type="text" maxlength="4" class="pp_count" value="0" name="count[1]" min="0">
                        <button class="pp_order_plus" type="button"><i class="fa fa-plus"></i>+</button>
                        </td>





                        Please take a look here for multiple textbox.






                        share|improve this answer




























                          0














                          I suggest you to bind only one time change function to input box.






                          $(function(){ 

                          $('.pp_order_min').on("click", function(){
                          var currentObj=$(this);
                          debugger;
                          if(currentObj.next().val() === '') return;
                          if(currentObj.next().val() !== '0') currentObj.next().val(parseInt(currentObj.next().val()) - 1);
                          currentObj.next().change(); // next is the input field
                          });
                          $('.pp_order_plus').on("click", function(){
                          var currentObj=$(this);
                          debugger;
                          if(currentObj.prev().val() === '') return;
                          if(currentObj.prev().val() !== '999') currentObj.prev().val(parseInt(currentObj.prev().val()) + 1);
                          currentObj.prev().change(); // prev is the input field
                          });
                          $('.pp_count').on('change input', function(){ // also tried 'on change' etc
                          var amt = $(this).val();
                          console.log(amt)
                          });
                          $('.pp_count').each(function(){ // using each since there are more input fields like this
                          $(this).click();//
                          });
                          });

                          <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
                          <td class="amt">
                          <button class="pp_order_min" type="button"><i class="fa fa-minus"></i>-</button>
                          <input type="text" maxlength="4" class="pp_count" value="0" name="count[1]" min="0">
                          <button class="pp_order_plus" type="button"><i class="fa fa-plus"></i>+</button>
                          </td>





                          Please take a look here for multiple textbox.






                          share|improve this answer


























                            0












                            0








                            0







                            I suggest you to bind only one time change function to input box.






                            $(function(){ 

                            $('.pp_order_min').on("click", function(){
                            var currentObj=$(this);
                            debugger;
                            if(currentObj.next().val() === '') return;
                            if(currentObj.next().val() !== '0') currentObj.next().val(parseInt(currentObj.next().val()) - 1);
                            currentObj.next().change(); // next is the input field
                            });
                            $('.pp_order_plus').on("click", function(){
                            var currentObj=$(this);
                            debugger;
                            if(currentObj.prev().val() === '') return;
                            if(currentObj.prev().val() !== '999') currentObj.prev().val(parseInt(currentObj.prev().val()) + 1);
                            currentObj.prev().change(); // prev is the input field
                            });
                            $('.pp_count').on('change input', function(){ // also tried 'on change' etc
                            var amt = $(this).val();
                            console.log(amt)
                            });
                            $('.pp_count').each(function(){ // using each since there are more input fields like this
                            $(this).click();//
                            });
                            });

                            <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
                            <td class="amt">
                            <button class="pp_order_min" type="button"><i class="fa fa-minus"></i>-</button>
                            <input type="text" maxlength="4" class="pp_count" value="0" name="count[1]" min="0">
                            <button class="pp_order_plus" type="button"><i class="fa fa-plus"></i>+</button>
                            </td>





                            Please take a look here for multiple textbox.






                            share|improve this answer













                            I suggest you to bind only one time change function to input box.






                            $(function(){ 

                            $('.pp_order_min').on("click", function(){
                            var currentObj=$(this);
                            debugger;
                            if(currentObj.next().val() === '') return;
                            if(currentObj.next().val() !== '0') currentObj.next().val(parseInt(currentObj.next().val()) - 1);
                            currentObj.next().change(); // next is the input field
                            });
                            $('.pp_order_plus').on("click", function(){
                            var currentObj=$(this);
                            debugger;
                            if(currentObj.prev().val() === '') return;
                            if(currentObj.prev().val() !== '999') currentObj.prev().val(parseInt(currentObj.prev().val()) + 1);
                            currentObj.prev().change(); // prev is the input field
                            });
                            $('.pp_count').on('change input', function(){ // also tried 'on change' etc
                            var amt = $(this).val();
                            console.log(amt)
                            });
                            $('.pp_count').each(function(){ // using each since there are more input fields like this
                            $(this).click();//
                            });
                            });

                            <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
                            <td class="amt">
                            <button class="pp_order_min" type="button"><i class="fa fa-minus"></i>-</button>
                            <input type="text" maxlength="4" class="pp_count" value="0" name="count[1]" min="0">
                            <button class="pp_order_plus" type="button"><i class="fa fa-plus"></i>+</button>
                            </td>





                            Please take a look here for multiple textbox.






                            $(function(){ 

                            $('.pp_order_min').on("click", function(){
                            var currentObj=$(this);
                            debugger;
                            if(currentObj.next().val() === '') return;
                            if(currentObj.next().val() !== '0') currentObj.next().val(parseInt(currentObj.next().val()) - 1);
                            currentObj.next().change(); // next is the input field
                            });
                            $('.pp_order_plus').on("click", function(){
                            var currentObj=$(this);
                            debugger;
                            if(currentObj.prev().val() === '') return;
                            if(currentObj.prev().val() !== '999') currentObj.prev().val(parseInt(currentObj.prev().val()) + 1);
                            currentObj.prev().change(); // prev is the input field
                            });
                            $('.pp_count').on('change input', function(){ // also tried 'on change' etc
                            var amt = $(this).val();
                            console.log(amt)
                            });
                            $('.pp_count').each(function(){ // using each since there are more input fields like this
                            $(this).click();//
                            });
                            });

                            <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
                            <td class="amt">
                            <button class="pp_order_min" type="button"><i class="fa fa-minus"></i>-</button>
                            <input type="text" maxlength="4" class="pp_count" value="0" name="count[1]" min="0">
                            <button class="pp_order_plus" type="button"><i class="fa fa-plus"></i>+</button>
                            </td>





                            $(function(){ 

                            $('.pp_order_min').on("click", function(){
                            var currentObj=$(this);
                            debugger;
                            if(currentObj.next().val() === '') return;
                            if(currentObj.next().val() !== '0') currentObj.next().val(parseInt(currentObj.next().val()) - 1);
                            currentObj.next().change(); // next is the input field
                            });
                            $('.pp_order_plus').on("click", function(){
                            var currentObj=$(this);
                            debugger;
                            if(currentObj.prev().val() === '') return;
                            if(currentObj.prev().val() !== '999') currentObj.prev().val(parseInt(currentObj.prev().val()) + 1);
                            currentObj.prev().change(); // prev is the input field
                            });
                            $('.pp_count').on('change input', function(){ // also tried 'on change' etc
                            var amt = $(this).val();
                            console.log(amt)
                            });
                            $('.pp_count').each(function(){ // using each since there are more input fields like this
                            $(this).click();//
                            });
                            });

                            <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
                            <td class="amt">
                            <button class="pp_order_min" type="button"><i class="fa fa-minus"></i>-</button>
                            <input type="text" maxlength="4" class="pp_count" value="0" name="count[1]" min="0">
                            <button class="pp_order_plus" type="button"><i class="fa fa-plus"></i>+</button>
                            </td>






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 20 '18 at 13:21









                            Negi RoxNegi Rox

                            1,7051511




                            1,7051511






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53393445%2fjquery-change-textfield-value-and-run-function%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                MongoDB - Not Authorized To Execute Command

                                How to fix TextFormField cause rebuild widget in Flutter

                                in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith