devxlogo

Dynamically Changing Table Values

Dynamically Changing Table Values

Question:
I have a table that contains the values returned from a SQL database. I have created a division within each cell. The ID value for the division is the keyvalue of the recordset. On mouseover, the DIV that I store the name of the current DIV in is a hidden form input. I also move and make visible a select input item and set its value to the value currently in the table cell. The idea is that the user picks a new value and I update the table with the new value. I set the new value using this function:

function selectSupported(oObject){	var strSelText =oObject.options[oObject.selectedIndex].text //oObject is theselect input	var strCurValue =document.all.item(document.all.hidCurSupported.value).innerText//getting the value currently in the table	if (strSelText != strCurValue)document.all.item(document.all.hidCurSupported.value).innerText = strSelText; //set the new value}

This code works, however, it only works once. After I set the inner text of the DIV in the table cell, the table cell no longer responds to mouse over events. Any ideas?

Answer:
While I can’t see anything obvious, here’s a couple of possibilities that you may want to explore. You may need to check that you’re not inadvertently creating two DIVs with the same ID. If that happens, then referencing gets screwed up because you inadvertently create a collection with that ID. For example:

This is line 1
This is line 2

You’ll generate an error if you then attempt to say in a script,

var data=document.all("mydoc").innerText

At this point, you actually need to refer to the entities as if they were a collection:

var data=document.all("mydoc")[1].innerTextalert data

This will pop-up an alert box saying “This is line 2”.

You should also make sure you’re not wiping out the object that contains the mouseover handler when you do the innerText call. I presume that you invoke the onchange event handler in the

Finally, you may want to check the general validity of your code. Often times, especially in complex scripts that are heavily HTML object centric, a bad script (or an illegal reference) won’t necessarily raise an error, but rather it’ll just cause everything after it to fail. The fact that your routine works once makes me suspect that this may indeed be the culprit. (I spent the better part of today tracking down just such an error).

devx-admin

Share the Post: