We are trying to use a Javascript incrementer and decrementer on an ASP.Net textbox to up the numerical value. The default textbox is set at 0.
We append 2 divs that fire Javascript to increment and decrement the value in the ASP.Net textbox. The values get changed BUT...
We are also having issue where the Javascript is supposedly supposed to prevent the value from going below 0. However, when we decrement below 0 the textbox goes blank and then when we try to increment, we get a NaN value. My plan is to just make the decrementing button disappear when the value gets to '0'. Any help is appreciated. Is it possible to use a Javascript/jQuery incrementer/decrementer on an ASP.Net textbox?
Any pointers on how to make the decrementer button to disappear when the value hit's '0' and reappear when the value is above '0'. PLUS if it is possible to use a Javascript incrementing/decrementing on an ASP.Net textbox.
Thanks in advance.
Here is my Javascript below:
if (Modernizr.mq("screen and (max-width:767px)")) {
if ($('.product-variant-list td span.quantity input.numerictextboxtext:not([disabled])')) {
$('input.numerictextboxtext:not([disabled])').parent().append('<div class="incButton button">+</div><div class="decButton button">-</div>');
}
if ($('input.numerictextboxtext').val() == 0) {
$(".decButton").hide();
}
if ($('input.numerictextboxtext').val() >= 1) {
$(".decButton").show();
}
$(".button").click(function () {
var $button = $(this);
var oldValue = $button.parent().find("input.numerictextboxtext").val();
//TODO: See if you can show and hide button on based on value of textbox
if(oldValue == 0){
$(".decButton").hide();
}
if (oldValue >= 1) {
$(".decButton").show();
}
if ($button.text() == "+") {
var newVal = parseFloat(oldValue) + 1;
} else {
// Don't allow decrementing below zero - supposedly. But this does not work in our case
if (oldValue >= 1) {
var newVal = parseFloat(oldValue) - 1;
}
}
$button.parent().find("input.numerictextboxtext").val(newVal);
});//End button click
}//End Modernizr check