<html>
<head>
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<label for="qty">Quantity</label>
<input id="qty" value="0" />
<button onclick="modify_qty(-1)">-1</button>
<button onclick="modify_qty(1)">+1</button>
</body>
</html>
// sample solution to script.js
function modify_qty(val) {
var qty = parseFloat(document.getElementById('qty').value);
var new_qty = qty + val;
if (new_qty < 0) {
new_qty = 0;
}
document.getElementById('qty').value = parseFloat(new_qty);
return new_qty;
}
No comments:
Post a Comment