I am new to JavaScript. I want to write a JavaScript to calculate the area of various geometries.The program takes dimensions from a user.I want to know the what does [0] show in following line:
document.getElementsByName('ID OF INPUT FIELD')[0].value;
Can anyone give me name of this thing (i.e array so something else !) so that I can learn it or please give me a link to understand this.
<script>
function func() {
var base = document.getElementsByName('width')[0].value; // ---> what [0] shows?
var height = document.getElementsByName('height')[0].value;
var out = (1/2) * parseFloat(base) * parseFloat(height);
document.getElementsByName('output')[0].value= out;
}
</script>
<body>
<html>
<br><center> <button onClick="func()">Calculate Area</button></center><br>
<table>
<tr><td align="right">Width (b):</td>
<td align="left"><input type="textbox" name="width"></input><br></td><br><br>
<tr><td align="right">Height (h):</td>
<td align="left"><input type="textbox" name="height"></input><br></td><br><br>
<tr>
<td align="right">The area is: </td>
<td align="left"><input type="textbox" name="output"></input><br>
</td>
</table>
</body>
</html>