`
JavaScript
x
17
17
1
<input type="number" id="qty">
2
<input type="button" onclick="add()" value="Add">
3
4
<script>
5
function add(){
6
qty = document.getElementById('qty').value
7
if(qty>0){
8
var tot = qty*25
9
document.write(tot)
10
11
}else{
12
qty = ""
13
alert("no")
14
}
15
}
16
</script>
17
‘qty=””‘ is the correct way as mentioned on google. but not working for me.
Advertisement
Answer
Try
JavaScript
1
2
1
document.getElementById("qty").value = "";
2
and cast qty to number in your if
JavaScript
1
2
1
if(Number(qty) > 0)
2