user94 user94 - 3 months ago 5
HTML Question

how to access contents of a text box using name of the input text box element in javascript?



function display() {
var x = document.nid.value;
//document.body.innerHTML=x;
document.write(x);
}

<head>
<meta charset="ISO-8859-1">
<title>Print Reverse of a number</title>
</head>

<body>
<table>
<tr>
<td>
Enter number
</td>
<td>
<input type="number" size="20" name="nid">
</td>
</tr>
<tr>
<td align="center" colspan="2">
<input type="submit" value="submit" onclick="display()">
</td>
</tr>
</table>
</body>




Answer

Your should replace

var x = document.nid.value

By

x = document.getElementsByName("nid")[0].value;
Comments