467,867 Members | 1,323 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,867 developers. It's quick & easy.

getElementByID value

I have this tag:

<span id="member_id"></span>

and I want to change the value to "Member"

why can't I do:

document.getElementByID("member_id").value = "Member";

Any help is appreciated.

Mike

Jul 20 '05 #1
  • viewed: 150118
Share:
4 Replies
or it is:

document.getElementByID("member_id").innerHTML = "Member";

Michael Hill wrote:
I have this tag:

<span id="member_id"></span>

and I want to change the value to "Member"

why can't I do:

document.getElementByID("member_id").value = "Member";

Any help is appreciated.

Mike


Jul 20 '05 #2
or it is:

document.getElementByID("member_id").innerHTML = "Member";

Michael Hill wrote:
I have this tag:

<span id="member_id"></span>

and I want to change the value to "Member"

why can't I do:

document.getElementByID("member_id").value = "Member";

Any help is appreciated.

Mike


Jul 20 '05 #3
In article <3F***************@ram.lmtas.lmco.com>,
hi****@ram.lmtas.lmco.com enlightened us with...
I have this tag:

<span id="member_id"></span>

and I want to change the value to "Member"

why can't I do:

document.getElementByID("member_id").value = "Member";


There is no value property to a span element.
I assume you want the text "Member" displayed in that span.

var e = document.getElementById("member_id");
var oTextNode = document.createTextNode("Member");
var oReplaceNode = e.childNodes(0);
oReplaceNode.replaceNode(oTextNode);

You could also use innerHTML, but I have heard it isn't cross-browser
enough. It would be

document.getElementById("member_id").innerHTML = "Member";

--
~kaeli~
Why do they sterilize the needles for lethal injections?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #4
It's getElementById(), not getElementByID(), so it would be:

document.getElementById("member_id").innerHTML

But:

document.getElementById("member_id").appendChild(d ocument.createTextNode("Member"));

is more standards compliant. Please note that the line above is
only required when initially appending text to the empty span.
Once the text node exists, you only need to change it's value. If
you're certain that the span will always only contain a text
node, you could use something like:

if (document.getElementById("member_id").firstChild == null) {

document.getElementById("member_id").appendChild(d ocument.createTextNode("Member"));

} else {
document.getElementById("member_id").firstChild.no deValue =
"Something Else";
}

Michael Hill wrote:
or it is:

document.getElementByID("member_id").innerHTML = "Member";

Michael Hill wrote:
I have this tag:

<span id="member_id"></span>

and I want to change the value to "Member"

why can't I do:

document.getElementByID("member_id").value = "Member";

Any help is appreciated.

Mike


--
| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available
at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

By using this site, you agree to our Privacy Policy and Terms of Use.