`
<input type="number" id="qty"> <input type="button" onclick="add()" value="Add"> <script> function add(){ qty = document.getElementById('qty').value if(qty>0){ var tot = qty*25 document.write(tot) }else{ qty = "" alert("no") } } </script>
‘qty=””‘ is the correct way as mentioned on google. but not working for me.
Advertisement
Answer
Try
document.getElementById("qty").value = "";
and cast qty to number in your if
if(Number(qty) > 0)