Remove negative signal from input number

0

I have the following code in jquery:

$.each(data.Dados, function (i, val) {
   tr += '<tr>';
   tr += '<td><div class="product" style="margin-bottom:0;padding-bottom:0;"><div class="product-info" style="margin-bottom:0;padding-bottom:0;"><h3 class="product-title">' + data.Dados[i].post_title + '</h3></div></div></td>';
   tr += '<td style="text-align:center;" class="price-col" data-id-cart="' + data.Dados[i].post_id + '" id="preco_' + data.Dados[i].post_id + '">' + data.Dados[i].post_valor + '</td>';
   tr += '<td style="text-align:center;padding:0;" class="quantity-col"><input data-mask="00" data-mask-selectonfocus="true" style="margin:0;" onfocus="campoTexto(this, 1)" onblur="campoTexto(this, 0)" type="number" onChange="Multiplica(' + data.Dados[i].post_id + ',' + data.Dados[i].post_quantidade + ' )" class="form-control qtd_' + data.Dados[i].post_id + '" ' + data.Dados[i].disabled + ' min="1" max="' + data.Dados[i].post_quantidade + '" placeholder="0" required=""></td>';
   tr += '<td style="text-align:center;" class="subtotal-col">R$<span id="sub_' + data.Dados[i].post_id + '">0.00</span></td>';
   tr += '</tr>';
});

I need to clear the - (minus) sign of this blessed input field, because if a client chooses -1 the real-time values will be negative, so I can not leave this -1 at all, if

asked by anonymous 09.11.2017 / 00:06

2 answers

3

Some solutions:

<input min='0' type="number" onkeypress="return (event.charCode == 8 || event.charCode == 0) ? null : event.charCode >= 48 && event.charCode <= 57">

or

<input type="number" onkeypress="return event.charCode >= 48" min="1" >

or even this

<input type="number" min="0" oninput="this.value = Math.abs(this.value)">

or who knows this

<input type="number" name="test" min=0 oninput="validity.valid||(value='');">
    
09.11.2017 / 00:17
0

use the property min="0"

<input data-mask="00" data-mask-selectonfocus="true" style="margin:0;" onfocus="campoTexto(this, 1)" onblur="campoTexto(this, 0)" type="number" onChange="Multiplica(' + data.Dados[i].post_id + ',' + data.Dados[i].post_quantidade + ' )" class="form-control qtd_' + data.Dados[i].post_id + '" ' + data.Dados[i].disabled + ' min="1" max="' + data.Dados[i].post_quantidade + '" placeholder="0" required="" min="0">
    
09.11.2017 / 00:17