Reputation: 1019
My input tag looks like this:
<input type="text" name="kkk" value="dis" disabled="disabled"></input>
This is my JavaScript function
function get(){
alert(document.getElementById("kkk").value);
}
Though I don't have id for the above tag value gets printed when using getElementById
. Can any one explain me the behavior?
Upvotes: 1
Views: 2178
Reputation: 1073988
My guess is you're using Internet Explorer, which uses name
as well as id
(in several versions); more here. Microsoft even documents this, but it's out-of-spec behavior which is fixed in IE8 and above (in standards mode).
Upvotes: 3
Reputation: 943108
You are experiencing error recovery / backwards compatibility features that appear in some browsers (related to a time when giving an element a name or an id created a global variable of the same name), particularly when a standards-mode triggering Doctype is missing. You should not depend on this.
Upvotes: 4