Reputation: 97
I have a simple numeric keypad with buttons which work as expected. You click a button and that number is displayed in the text area.
My question concerns adding 2 buttons to the keypad that will (+) increase or (-) decrease the number in the text area.
Please see the demo here, http://jsfiddle.net/froze1906/cHPvx/
What do I need to add to activate the + and - buttons?
Upvotes: 1
Views: 598
Reputation: 144699
Try the following:
$('.dec').click(function(){
var val = parseInt($('#number_field').val(), 10);
if (val != 0) {
$('#number_field').val(val - 1)
}
})
$('.inc').click(function(){
var val = parseInt($('#number_field').val(), 10);
if (val != 4) {
$('#number_field').val(val + 1)
}
})
Upvotes: 1