Javascript : simple

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
littlecoder
Forum Commoner
Posts: 26
Joined: Fri Oct 17, 2008 4:36 am

Javascript : simple

Post 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>
User avatar
deeessay
Forum Commoner
Posts: 55
Joined: Sat May 24, 2008 1:02 am

Re: Javascript : simple

Post by deeessay »

When using getElementById some browsers, like IE, will use the name attribute value, when id is not given...
Post Reply