2 replies [Last post]
dcbohn
Offline
newbie
Last seen: 11 years 23 weeks ago
Joined: 2003-03-21
Posts: 4
Points: 0

I am inserting a Row into a table and in one of the TD elements I am inserting a SELECT box. I am using insertBefore() to insert the Row, and appendChild(oCell) to insert the TD tags. I am setting up a string (abc) to hold the SELECT tag, Ex. MyElm.innerHTML = abc. My problem is that the in the SELECT element the item disolayed is the one after the SELECTED tag. I think I have used this method in the past successfully, if not, then one close to it. A code snippet is below.

oCell=document.createElement("TD");
var abc = "<SELECT name='PayMeth"+iPRow+"' id='PayMeth"+iPRow+"' onChange='"+sOnChange+"' style='width:120;'>";

for (var ii = 1; ii < (jPMArray.length); ii++) {
abc = abc + "<OPTION value='"+jPMArray[ii].pmid+"' "
if (oPMIData.pay_meth == jPMArray[ii].pmid) abc = abc + " SELECTED ";
abc = abc + ">"+jPMArray[ii].pdesc+"</OPTION>";
}

abc = abc + "</SELECT>";
oCell.innerHTML = abc;
oRow.appendChild(oCell);

Tags:
Tony
Tony's picture
Offline
Moderator
Brisbane
Last seen: 9 hours 40 min ago
Brisbane
Timezone: GMT+10
Joined: 2003-03-12
Posts: 5108
Points: 2704

incorrect SELECTED in a DHTML in a table cell

Hi dcbohn,
Could you post an link or attach an example.

dcbohn
Offline
newbie
Last seen: 11 years 23 weeks ago
Joined: 2003-03-21
Posts: 4
Points: 0

incorrect SELECTED in a DHTML in a table cell

Laughing out loud
I found the problem, it was someone else's code who was setting the SELECTED attribute in a differnet part of the code. I turned his off and mine functioned properly. But I did think of the question of effeciency. Is it more efficent to use insertHTML with a large group of tags or use the DOM to insert a tag at a time?