File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes document.getElementById() not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "document.getElementById() not working" Watch "document.getElementById() not working" New topic
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
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6

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
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6

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
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6

puja shaw
Ranch Hand

Joined: Nov 06, 2012
Posts: 32


wow..Thanks a lot..:-D !
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6

You are most welcome.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
JavaScript is case sensitive, Value != value
puja shaw
Ranch Hand

Joined: Nov 06, 2012
Posts: 32
oh ok..Thanks
 
GeeCON Prague 2014
 
subject: document.getElementById() not working