| Author |
document.getElementById() not working
|
puja shaw
Ranch Hand
Joined: Nov 06, 2012
Posts: 32
|
|
i found out that the document.getElementById() is not working.Can anyone help me with this.Please try the below given code and tell me if it works.The rest of the tags are working except for the getElementById thing.
<html>
<body>
<script>
alert(document.getElementById('mine').value);
</script>
<input type="text" id="mine" value="ooo"/>
</body>
</html>
|
 |
Swastik Dey
Ranch Hand
Joined: Jan 08, 2009
Posts: 1195
|
|
Puja,
Your script tag is inside body and before input tag. So when it tries to execute it does not find that id. If you execute in IE, with display notification with every script error option enabled, it should an error that id not found. It should come after input tag is placed.
|
Swastik
|
 |
puja shaw
Ranch Hand
Joined: Nov 06, 2012
Posts: 32
|
|
|
thankyou:-)!
|
 |
Swastik Dey
Ranch Hand
Joined: Jan 08, 2009
Posts: 1195
|
|
|
You are most welcome.
|
 |
puja shaw
Ranch Hand
Joined: Nov 06, 2012
Posts: 32
|
|
i am stuck with a problem regarding javascript again.I am trying to add an option to the select box and add a value to that option through javascript.The option is getting added but the value is not being shown in that option.I am not able to figure out where the problem lies.Can you please help me.
<html>
<body>
<select id="SelectHidden" name="SelectHiddenThing" onClick="MyFunction1();">
<select/>
<script>
function MyFunction1(){
var box=document.getElementById("SelectHidden");
var anoption=document.createElement("OPTION");
alert("*******"+anoption);
box.options.add(anoption);
anoption.innerText="two";
anoption.Value="2"
};
</script>
</body>
</html>
|
 |
Swastik Dey
Ranch Hand
Joined: Jan 08, 2009
Posts: 1195
|
|
|
|
 |
puja shaw
Ranch Hand
Joined: Nov 06, 2012
Posts: 32
|
|
wow..Thanks a lot..:-D !
|
 |
Swastik Dey
Ranch Hand
Joined: Jan 08, 2009
Posts: 1195
|
|
|
You are most welcome.
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15357
|
|
|
JavaScript is case sensitive, Value != value
|
 |
puja shaw
Ranch Hand
Joined: Nov 06, 2012
Posts: 32
|
|
|
oh ok..Thanks
|
 |
 |
|
|
subject: document.getElementById() not working
|
|
|