N
N. Sloane
Hi,
I've been having a bit of a problem over the last couple of days, as I
have been using some code to dynamically add and remove rows to a
table, then I loop through all the elements looking for ones with
specific names, then submit this via an AJAX call to a PHP script.
I've done this before successfully, but for some reason this times it
works in Internet Explorer, but not Firefox, whereas previously I've
had no problem get this to work in both.
I've included some code below. The main item is cell 3, as it will add
new input boxes called rental1, rental2, rental3, etc:
function addRowToTable()
{
var tbl = document.getElementById('pb');
var lastRow = tbl.rows.length;
// if there's no header row in the table, then iteration = lastRow +
1
var iteration = lastRow;
var row = tbl.insertRow(lastRow);
nextYear = parseInt(nextYear) + parseInt(lastRow);
// cell 1
var cellOne = row.insertCell(0);
var textNode = document.createTextNode("");
cellOne.appendChild(textNode);
// cell 2
var cellTwo = row.insertCell(1);
var textNode = document.createTextNode("");
cellTwo.appendChild(textNode);
cellTwo.innerHTML = "<em>and / or Rental Payment
(£:</em>";
cellTwo.setAttribute("style", "text-align: left; ");
if (iteration % 2 == 0) {cellTwo.setAttribute("class", "b1")} else
{cellTwo.setAttribute("class", "b2")}
// cell 3
var cellThree = row.insertCell(2);
var el = document.createElement('input');
el.type = 'text';
el.name = 'rental' + iteration;
el.id = 'rental' + iteration;
el.size = 10;
if (iteration % 2 == 0) {cellThree.setAttribute("class", "b1")} else
{cellThree.setAttribute("class", "b2")}
cellThree.appendChild(el);
// cell 4
var cellFour = row.insertCell(3);
var textNode = document.createTextNode("");
cellFour.appendChild(textNode);
cellFour.innerHTML = "<em>Year (yyyy)</em>";
cellFour.setAttribute("style", "text-align: left;");
if (iteration % 2 == 0) {cellFour.setAttribute("class", "b1")} else
{cellFour.setAttribute("class", "b2")}
// cell 5
var cellFive = row.insertCell(4);
var textNode = document.createTextNode(nextYear);
cellFive.appendChild(textNode);
cellFive.setAttribute("style", "text-align: left;");
if (iteration % 2 == 0) {cellFive.setAttribute("class", "b1")} else
{cellFive.setAttribute("class", "b2")}
// cell 6
var cellSix = row.insertCell(5);
}
Now, I use the following code to loop through every element on the
page, and use a regex to locate all elements with the name "rental" in
it:
var re = /rental[0-9]{1,}/;
var eleNum = window.document.duty.elements.length; // duty is the
name of the form
for (var i=0;i < eleNum;i++){
ele = window.document.duty.elements.name;
if(re.test(ele)) {eleval =
window.document.duty.elements.value;
// Further Error checking code goes here
}
When I check the DOM Inspector in Firefox, input elements such as
rental1, rental2, etc, are clearly showing in the DOM. However,
Firefox fails to pick the dynamically added elements and fails to
submit them. However, IE does.
I have used virtually identical code in a similar application, and
Firefox detects them without a problem.
I'm totally vexed as to what is going wrong here. Does anyone have any
ideas?
Many Thanks
Regards
Neil.
I've been having a bit of a problem over the last couple of days, as I
have been using some code to dynamically add and remove rows to a
table, then I loop through all the elements looking for ones with
specific names, then submit this via an AJAX call to a PHP script.
I've done this before successfully, but for some reason this times it
works in Internet Explorer, but not Firefox, whereas previously I've
had no problem get this to work in both.
I've included some code below. The main item is cell 3, as it will add
new input boxes called rental1, rental2, rental3, etc:
function addRowToTable()
{
var tbl = document.getElementById('pb');
var lastRow = tbl.rows.length;
// if there's no header row in the table, then iteration = lastRow +
1
var iteration = lastRow;
var row = tbl.insertRow(lastRow);
nextYear = parseInt(nextYear) + parseInt(lastRow);
// cell 1
var cellOne = row.insertCell(0);
var textNode = document.createTextNode("");
cellOne.appendChild(textNode);
// cell 2
var cellTwo = row.insertCell(1);
var textNode = document.createTextNode("");
cellTwo.appendChild(textNode);
cellTwo.innerHTML = "<em>and / or Rental Payment
(£:</em>";
cellTwo.setAttribute("style", "text-align: left; ");
if (iteration % 2 == 0) {cellTwo.setAttribute("class", "b1")} else
{cellTwo.setAttribute("class", "b2")}
// cell 3
var cellThree = row.insertCell(2);
var el = document.createElement('input');
el.type = 'text';
el.name = 'rental' + iteration;
el.id = 'rental' + iteration;
el.size = 10;
if (iteration % 2 == 0) {cellThree.setAttribute("class", "b1")} else
{cellThree.setAttribute("class", "b2")}
cellThree.appendChild(el);
// cell 4
var cellFour = row.insertCell(3);
var textNode = document.createTextNode("");
cellFour.appendChild(textNode);
cellFour.innerHTML = "<em>Year (yyyy)</em>";
cellFour.setAttribute("style", "text-align: left;");
if (iteration % 2 == 0) {cellFour.setAttribute("class", "b1")} else
{cellFour.setAttribute("class", "b2")}
// cell 5
var cellFive = row.insertCell(4);
var textNode = document.createTextNode(nextYear);
cellFive.appendChild(textNode);
cellFive.setAttribute("style", "text-align: left;");
if (iteration % 2 == 0) {cellFive.setAttribute("class", "b1")} else
{cellFive.setAttribute("class", "b2")}
// cell 6
var cellSix = row.insertCell(5);
}
Now, I use the following code to loop through every element on the
page, and use a regex to locate all elements with the name "rental" in
it:
var re = /rental[0-9]{1,}/;
var eleNum = window.document.duty.elements.length; // duty is the
name of the form
for (var i=0;i < eleNum;i++){
ele = window.document.duty.elements.name;
if(re.test(ele)) {eleval =
window.document.duty.elements.value;
// Further Error checking code goes here
}
When I check the DOM Inspector in Firefox, input elements such as
rental1, rental2, etc, are clearly showing in the DOM. However,
Firefox fails to pick the dynamically added elements and fails to
submit them. However, IE does.
I have used virtually identical code in a similar application, and
Firefox detects them without a problem.
I'm totally vexed as to what is going wrong here. Does anyone have any
ideas?
Many Thanks
Regards
Neil.