Page 1 of 1

Javascript : simple

Posted: Wed Nov 26, 2008 10:01 pm
by littlecoder
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>

Re: Javascript : simple

Posted: Thu Nov 27, 2008 12:17 am
by deeessay
When using getElementById some browsers, like IE, will use the name attribute value, when id is not given...