Plus / Minus jquery does not work

2

I can not change the value of the id="value" input when you click .minus or .plus , what should I do to solve?

<input type="button" value="+" class="plus">                                                

<input  id="value" step="1" max="99" min="1" title="Qty" class="qty" type="number" name="prod[<?php echo $result['id']?>]" value="<?php echo $result['quantity']?>" size="4" />

<input type="button" value="-" class="minus">

jquery

$('.plus').click(function() { changeValue(1); });
$('.minus').click(function() { changeValue(-1); });

function changeValue(val) {
    var container = $('#value');
    var current = parseInt(container.html(), 10);

    container.html(Math.max(0, current + val).toString());
}
    
asked by anonymous 27.08.2018 / 21:39

1 answer

0

Change% from% to% with%. The container.html() serves to get the inner HTML of the element, not the value. The container.val() yes will get the value of .html() .

$('.plus').click(function() { changeValue(1); });
$('.minus').click(function() { changeValue(-1); });

function changeValue(val) {
    var container = $('#value');
    var current = parseInt(container.val(), 10);
    container.val(Math.max(0, current + val).toString());
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><inputtype="button" value="+" class="plus">                                                

<input  id="value" step="1" max="99" min="1" title="Qty" class="qty" type="number" name="nome" value="3" size="4">

<input type="button" value="-" class="minus">
    
27.08.2018 / 21:49