I wish to set a maximum number input in an "input type=number" based on the amount in the database. Currently, I am trying for it to work base on data-max before i try getting my max value from my database, however it cant seem to work.
It has been asked before previously here, however I cant understand it still: Set maximum number input text from database in php/javascript
HTML:
<div class="ui-block-a">
<div id="test">
<input type="button" value="-" class="minus" id="jumlah" name="jumlah">
</div>
</div>
<div class="ui-block-b">
<input type="number" min="1" max="10" id="quantity" value="0" name="quantity" title="Qty" class="input-text qty text" size="6" pattern="" inputmode="" data-max="3" onkeyup="check(this);" readonly>
</div>
<div class="ui-block-c">
<div id="test2">
<input type="button" value="+" class="plus" id="jumlah2" name="jumlah2">
</div>
</div>
JS:
function check(quantity) {
div.addEventListener('click', function () { });
var max = quantity.getAttribute("data-max");
if (parseInt(quantity.value) > parseInt(max)) {
alert("Amount out of max!");
}
}