Connecting Tech Pros Worldwide Help | Site Map

getElementByID value

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 20th, 2005, 12:01 PM
Michael Hill
Guest
 
Posts: n/a
Default 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


  #2  
Old July 20th, 2005, 12:01 PM
Michael Hill
Guest
 
Posts: n/a
Default 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, 12:01 PM
Michael Hill
Guest
 
Posts: n/a
Default 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, 12:01 PM
kaeli
Guest
 
Posts: n/a
Default 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, 12:01 PM
Grant Wagner
Guest
 
Posts: n/a
Default 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


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.