This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes document.getElementById() not working Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply 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
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
    
    6
JavaScript is case sensitive, Value != value
puja shaw
Ranch Hand

Joined: Nov 06, 2012
Posts: 32
oh ok..Thanks
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: document.getElementById() not working
 
Similar Threads
Changing the text of a buton
string.replace()
How to access content of p tag
image preview
can we write javascript functions on struts tags?