Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > getElementByID value

Reply
Thread Tools

getElementByID value

 
 
Michael Hill
Guest
Posts: n/a
 
      11-21-2003
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

 
Reply With Quote
 
 
 
 
Michael Hill
Guest
Posts: n/a
 
      11-21-2003
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


 
Reply With Quote
 
 
 
 
Michael Hill
Guest
Posts: n/a
 
      11-21-2003
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


 
Reply With Quote
 
kaeli
Guest
Posts: n/a
 
      11-21-2003
In article <>,
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

 
Reply With Quote
 
Grant Wagner
Guest
Posts: n/a
 
      11-21-2003
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 <>

* 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
setting getElementById().value equal to variable value ll Javascript 2 08-22-2008 03:54 PM
getElementById returning null value Rob ASP .Net 4 01-23-2008 10:28 AM
getElementById does not work on returned value of DOMParser.parseFromString() edai Javascript 3 02-01-2007 02:31 PM
document.getElementById fails when assigning return value to variable with same name as id? weston Javascript 19 01-01-2006 08:22 PM
can't reset the left value of a DIV using document.getElementById(thisDiv).style.left = howFarLeft; lawrence Javascript 13 09-04-2004 09:07 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57