• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

document.getElementById() not working

 
puja shaw
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1602
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


 
puja shaw
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thankyou:-)!
 
Swastik Dey
Rancher
Posts: 1602
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are most welcome.
 
puja shaw
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Rancher
Posts: 1602
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
puja shaw
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


wow..Thanks a lot..:-D !
 
Swastik Dey
Rancher
Posts: 1602
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are most welcome.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JavaScript is case sensitive, Value != value
 
puja shaw
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh ok..Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic