Connecting Tech Pros Worldwide Help | Site Map

getElementByID value

  #1  
Old July 20th, 2005, 01:01 PM
Michael Hill
Guest
 
Posts: n/a
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

  #2  
Old July 20th, 2005, 01:01 PM
Michael Hill
Guest
 
Posts: n/a

re: getElementByID value


or it is:

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

Michael Hill wrote:
[color=blue]
> 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[/color]

  #3  
Old July 20th, 2005, 01:01 PM
Michael Hill
Guest
 
Posts: n/a

re: getElementByID value


or it is:

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

Michael Hill wrote:
[color=blue]
> 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[/color]

  #4  
Old July 20th, 2005, 01:01 PM
kaeli
Guest
 
Posts: n/a

re: getElementByID value


In article <3FBE3797.10F87FCC@ram.lmtas.lmco.com>,
hillmw@ram.lmtas.lmco.com enlightened us with...[color=blue]
> 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";
>[/color]

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

  #5  
Old July 20th, 2005, 01:01 PM
Grant Wagner
Guest
 
Posts: n/a

re: getElementByID value


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:
[color=blue]
> or it is:
>
> document.getElementByID("member_id").innerHTML = "Member";
>
> Michael Hill wrote:
>[color=green]
> > 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[/color][/color]

--
| Grant Wagner <gwagner@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


Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
getting the numeric value of a variable andersond answers 2 April 21st, 2009 11:09 AM
setting getElementById().value equal to variable value ll answers 3 August 22nd, 2008 04:55 PM
Putting a dialog box value into a specific GridView row RobertTheProgrammer answers 9 May 21st, 2008 06:47 PM
open source javascript project - trouble with document.getElementById lawrence answers 1 July 23rd, 2005 12:30 PM