Re: Change the same span element all the time
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Re: Change the same span element all the time

From: David <david.goodyear@gmail.com>
Date: Fri Apr 28 2006 - 20:33:15 CEST

Hi,

I basically have a label in a span line that i want updated for example
with key presses.

I literally just try to change the text all the time, but cannot seem
to get it to work. Any suggestions?

Thanks

David

Ronaldo Junior wrote:
> David wrote:
> > I'd really appreciate any help. Im trying to change a label over and
> > over again. I can change it the first time, by using the following
> > code, however it never works again, how can i do this so it uses the
> > same element name? This is driving me insane. On the second call to var
> > spanElm = document.getElementById("FirstNameLengthLabel"); spanElm is
> > set to NULL.
> >
> > <script language=javascript>
> >
> > function txtFirstNameUpdate()
> > {
> > var para = document.getElementById("ForenameCell");
> > alert (para);
> > var spanElm = document.getElementById("FirstNameLengthLabel");
> > alert (spanElm);
> > var newSpan = document.createElement("FirstNameLengthLabel");
> > alert (newSpan);
> > var newText = document.createTextNode("Next label");
> > alert (newText);
> > newSpan.appendChild(newText);
> >
> > var test = para.replaceChild(newSpan,spanElm);
> > }
>
> It won't work twice because the replaceChild method actually replaces
> the node, erasing it to give place to the other one to replace to.
> Therefore, the first node won't exist after the first call.
>
> I'd suggest something but I didn't figure what you're trying to do.
Received on Mon May 1 05:26:01 2006