Cart quantity increase or decrease using Javascript onclick function | 2my4edge

10 February 2022

Cart quantity increase or decrease using Javascript onclick function

OnClick increment or decrement value in input text for cart quantity value. here i'm going to help you in onclick increment value and decrement value, in input type cart quantity field. let see the code for on click increment and decrement.

onclick increment and decrement in input text

HTML CODE
 <div class="container">
<input type="button" onclick="decrementValue()" value="-" />
<input type="text" name="quantity" value="1" maxlength="2" max="10" size="1" id="number" />
<input type="button" onclick="incrementValue()" value="+" />
</div>

JAVA SCRIPT
 <script type="text/javascript">
function incrementValue()
{
    var value = parseInt(document.getElementById('number').value, 10);
    value = isNaN(value) ? 0 : value;
    if(value<10){
        value++;
            document.getElementById('number').value = value;
    }
}
function decrementValue()
{
    var value = parseInt(document.getElementById('number').value, 10);
    value = isNaN(value) ? 0 : value;
    if(value>1){
        value--;
            document.getElementById('number').value = value;
    }

}
</script>

Here i have given some condition in if condition, if you don't want just remove that code. i hope this will be really helpful to you. thanks for visiting.. keep visiting for more tutorial.


7 comments:

  1. Everything is skimmed left and the DIV's have flood covered up to clear the buoys. The marks are showcase square and message adjust right to get the network thing going. Pixel changes are made here and there to get things lining up right. I didn't invest much energy in this, so you might see some cross-program contrasts.

    ReplyDelete
  2. Writing a Blog or Article starts with the most critical component of all. The "Blog Post Title." If this is done correctly and keyword rich you can control 80% of the Organic Search engines traffic. Sending it to your website!
    homework is good for students debate

    ReplyDelete
  3. Was wondering how to make this work with multiple forms on the same page? I tried and it only targets the qty field of the first form.

    Thanks for the great script.

    ReplyDelete
  4. The marks are showcase square and message adjust right to get the network thing going Send Flowers to Norway Cheap

    ReplyDelete
  5. I learn from a good blog, your blog I have a great inspiration, thank you. Pakistan Gifts online

    ReplyDelete
  6. So luck to come across your excellent blog. Your blog brings me a great deal of fun.. Good luck with the site.
    manabadi degree 1st semester results

    ReplyDelete
  7. Hello everyone, was interesting to read your article. Usually i'm reading New York Times , but now i will read you too!

    ReplyDelete

^