Connecting Tech Pros Worldwide Forums | Help | Site Map

How to get the value of an id

Newbie
 
Join Date: Mar 2008
Posts: 2
#1: Mar 10 '08
I'm trying to get the value of an id. This is my code:

<span id="test">this value</span>
<script type="text/javascript">
var myVal = document.getElementById('test').value;
alert(myVal);
</script>

When I run it I get "undefined" in the alert window.
How can I get the value "this value" from the span?

Please help.

Newbie
 
Join Date: Mar 2008
Posts: 2
#2: Mar 10 '08

re: How to get the value of an id


I found it.
I should use document.getElementById('test').innerHTML;
numberwhun's Avatar
Site Moderator
 
Join Date: May 2007
Location: New Hampshire
Posts: 2,573
#3: Mar 10 '08

re: How to get the value of an id


Quote:

Originally Posted by El Milahi

I found it.
I should use document.getElementById('test').innerHTML;

I will move this over to the Javascript forum for further input by the users there, but next time, please post technical questions in their appropriate technical forum.

Regards,

Moderator
Reply