Javascript : simple
Posted: Wed Nov 26, 2008 10:01 pm
Hi,
I am curious about this simple Javascript code : I am getting the result , but the question is how is it that 'document.getElementById('txt').value' works even when I have not given the
'id' attribute in the textbox?
<html>
<head>
<script type="text/javascript">
function fn()
{
alert(document.getElementById('txt').value);
}
</script>
</head>
<body>
<input type="text" name="txt">
<input type="button" name="bt" value="Click" onClick="fn();">
</body>
</html>
I am curious about this simple Javascript code : I am getting the result , but the question is how is it that 'document.getElementById('txt').value' works even when I have not given the
'id' attribute in the textbox?
<html>
<head>
<script type="text/javascript">
function fn()
{
alert(document.getElementById('txt').value);
}
</script>
</head>
<body>
<input type="text" name="txt">
<input type="button" name="bt" value="Click" onClick="fn();">
</body>
</html>