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

Change the same span element all the time

From: David <david.goodyear@gmail.com>
Date: Fri Apr 28 2006 - 19:24:01 CEST

Hi,

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);
}

</script>

...<HTML>
<tr id="FormTableRow1">
                <td width="107">Förnamn :</td>
                <td width="388" id="ForenameCell"> <INPUT Name="txtFirstName" Size=10
 MaxLength=30 onkeypress="txtFirstNameUpdate()">&nbsp;
                <span id="FirstNameLengthLabel">First label</span>
                <td width="90">Efternamn :</td>
                <td><INPUT Name="txtLastName" Size=20 MaxLength=30> </td>
        </tr>
...<HTML>

Thanks for any help

David
Received on Mon May 1 05:25:49 2006