Cart quantity increment / decrement using Javascript onclick | 2my4edge

25 August 2015

Cart quantity increment / decrement using Javascript onclick

OnClick increment and decrement value in input text for cart quantity value. here i'm going to help you a 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.





RELATED POSTS : 


5 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. I enjoy a couple of from the Information which has been written, and particularly the comments posted I will definitely be visiting again
    Dissertation writing services

    ReplyDelete
  3. 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
  4. 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
  5. The marks are showcase square and message adjust right to get the network thing going Send Flowers to Norway Cheap

    ReplyDelete

^