javascript - Incremental Controls for Textboxes -
i have code adds 2 buttons increase , decrease quantity of text box works fine. i'm trying expand code work multiple text boxes. unfortunately, names of text boxes vary page page, i'm using class name that's shared text boxes , attempting increment text box that's closest each of incremental buttons i'm getting nan value of text boxes.
oddly enough, doesn't generate errors. nan console.log line.
if point me in right direction, appreciative...
single instance (working) : http://codepen.io/realto619/pen/iacab
multiple instances (not much...): http://codepen.io/realto619/pen/ytpcf
function increaseqty(e) { console.log("jquery('.qty').prev().val() = " + jquery('.qty').prev().val()); var qtytotal = parseint(jquery('.qty').prev().val()); jquery('.qty').prev().val(parseint(jquery('.qty').prev().val())+1); }
first bind event handler this: jquery('.increase').click(increaseqty);
should use this keyword textbox near button pressed.
try code:
function increaseqty(e) { var tb = jquery(this).closest('input'); tb.val(parseint(tb.val()) + 1); } the closest() function searches closest parent element matches selector.
Comments
Post a Comment