Help! Hook Up the Buttons


#1

Hi guys.

The instruction is this:

"Add onclick attributes to both of the buttons, calling the modify_qty() function."

See the html and JavaScript code below


<html>
<head>
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<label for="qty">Quantity</label>
<input id="qty" value="0" />
<button>-1</button>
<button>+1</button>

<script>
function modify_qty(val) {
    var qty = document.getElementById('qty').value;
    var new_qty = qty + val;
    
    if (new_qty < 0) {
        new_qty = 0;
    }
    
    document.getElementById('qty').value = new_qty;
    return new_qty;
}
</script>

</body>

</html>


#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.