H
HugeBob
Hi All,
I've written some Javascript that dynamically adds a row to an
existing table. It then adds table cells with radio buttons in each
cell. This script works fine in Firefox. But, in IE it only works up
to a point. The code follows. Everything happens as it should except
that the radio buttons don't function: i.e., you can't check any of
them.
var table = document.getElementById(IDArg);
var rows = table.getElementsByTagName("tr");
var insertionIndex=0, checkBoxID, currentIDNumber;
// Calculation insertion index
if (rows.length == 1)
insertionIndex = 1;
else
{
for (var i = 1; i < rows.length; i++)
{
currentIDNumber = parseInt(rows.id.substring(2));
checkBoxID = parseInt(id);
if (checkBoxID < currentIDNumber)
{
insertionIndex = i;
break;
}
}
if (insertionIndex == 0)
insertionIndex = rows.length;
}
var newHTMLTableRow = table.insertRow(insertionIndex); // Create
table row
newHTMLTableRow.setAttribute("id", "ps"+idArg); // Set its id
attribute
var rowLabelCell = document.createElement("td"); // Create row title
cell
rowLabelCell.setAttribute("class", "title"); // Set its class to
"title". NOT WORKING IN IE
rowLabelCell.setAttribute("width", "300"); // Set its width to 300
rowLabelCell.appendChild(document.createTextNode(textArg)); // Append
text node to the cell
var specSpanText = document.createElement("span"); // Create a span
specSpanText.setAttribute("class", "explanation"); // Set the span's
class
specSpanText.appendChild(document.createTextNode(" (specialized)
")); // Append text to the span
rowLabelCell.appendChild(specSpanText); // Append the span to the row
title cell
var radioCell1 = document.createElement("td");
radioCell1.align = "center";
var radioButton1 = document.createElement("input");
radioButton1.type = "radio";
radioButton1.name = nameArg;
radioButton1.value = valueArg;
if (defaultArg1 == radioButton1.value)
radioButton1.checked = true;
radioCell1.appendChild(radioButton1);
var radioCell2 = document.createElement("td");
radioCell2.align = "center";
var radioButton2 = document.createElement("input");
radioButton2.type = "radio";
radioButton2.name = nameArg;
radioButton2.value = valueArg;
if (defaultArg2 == radioButton2.value)
radioButton2.checked = true;
radioCell2.appendChild(radioButton2);
var radioCell3 = document.createElement("td");
radioCell3.align = "center";
var radioButton3 = document.createElement("input");
radioButton3.type = "radio";
radioButton3.name = nameArg;
radioButton3.value = valueArg;
if (defaultArg3 == radioButton3.value)
radioButton3.checked = true;
radioCell3.appendChild(radioButton3);
newHTMLTableRow.appendChild(rowLabelCell);
newHTMLTableRow.appendChild(radioCell1);
newHTMLTableRow.appendChild(radioCell2);
newHTMLTableRow.appendChild(radioCell3);
I've written some Javascript that dynamically adds a row to an
existing table. It then adds table cells with radio buttons in each
cell. This script works fine in Firefox. But, in IE it only works up
to a point. The code follows. Everything happens as it should except
that the radio buttons don't function: i.e., you can't check any of
them.
var table = document.getElementById(IDArg);
var rows = table.getElementsByTagName("tr");
var insertionIndex=0, checkBoxID, currentIDNumber;
// Calculation insertion index
if (rows.length == 1)
insertionIndex = 1;
else
{
for (var i = 1; i < rows.length; i++)
{
currentIDNumber = parseInt(rows.id.substring(2));
checkBoxID = parseInt(id);
if (checkBoxID < currentIDNumber)
{
insertionIndex = i;
break;
}
}
if (insertionIndex == 0)
insertionIndex = rows.length;
}
var newHTMLTableRow = table.insertRow(insertionIndex); // Create
table row
newHTMLTableRow.setAttribute("id", "ps"+idArg); // Set its id
attribute
var rowLabelCell = document.createElement("td"); // Create row title
cell
rowLabelCell.setAttribute("class", "title"); // Set its class to
"title". NOT WORKING IN IE
rowLabelCell.setAttribute("width", "300"); // Set its width to 300
rowLabelCell.appendChild(document.createTextNode(textArg)); // Append
text node to the cell
var specSpanText = document.createElement("span"); // Create a span
specSpanText.setAttribute("class", "explanation"); // Set the span's
class
specSpanText.appendChild(document.createTextNode(" (specialized)
")); // Append text to the span
rowLabelCell.appendChild(specSpanText); // Append the span to the row
title cell
var radioCell1 = document.createElement("td");
radioCell1.align = "center";
var radioButton1 = document.createElement("input");
radioButton1.type = "radio";
radioButton1.name = nameArg;
radioButton1.value = valueArg;
if (defaultArg1 == radioButton1.value)
radioButton1.checked = true;
radioCell1.appendChild(radioButton1);
var radioCell2 = document.createElement("td");
radioCell2.align = "center";
var radioButton2 = document.createElement("input");
radioButton2.type = "radio";
radioButton2.name = nameArg;
radioButton2.value = valueArg;
if (defaultArg2 == radioButton2.value)
radioButton2.checked = true;
radioCell2.appendChild(radioButton2);
var radioCell3 = document.createElement("td");
radioCell3.align = "center";
var radioButton3 = document.createElement("input");
radioButton3.type = "radio";
radioButton3.name = nameArg;
radioButton3.value = valueArg;
if (defaultArg3 == radioButton3.value)
radioButton3.checked = true;
radioCell3.appendChild(radioButton3);
newHTMLTableRow.appendChild(rowLabelCell);
newHTMLTableRow.appendChild(radioCell1);
newHTMLTableRow.appendChild(radioCell2);
newHTMLTableRow.appendChild(radioCell3);