Search code examples
javascriptheightgetelementbyidcalculatorarea

Calculate area from inputs in Javascript


I've got a very simple javascript calculator here but it doesn't seem to be working. I'm sure it's something very simple to solve but just can't see it. I've spent a while on it and thought I'd be better off asking here. Any suggestions? Thanks! http://jsfiddle.net/z98gb/7/

Width <input type="Text" name="width" size="4">  
Height <input type="Text" name="height" size="4" onkeyup=""> <br><br>
Area <input type="Text" name="area" id="area" size="4"> <br><br>
<input type="button" name="calculate" id="area" size="4" onclick="calculateArea()"    value="calculate">

And here's the javascript:

function calculateArea() {
var width = document.getElementById("width").value;
var height = document.getElementById("height").value;
var area = width * height;
document.getElementById("area").value = area;

}


Solution

  • You didn't specify an id for your input

    Working example : http://jsfiddle.net/z98gb/8/