help with cloneNode script
Date: 06/22/06
(Javascript Community) Keywords: html
I am trying to create a script that will add a new field when the user clicks on a link. I am using the cloneNode feature to take the existing field and make a new one based on that. This script works great in firefox on my mac, but fails on IE 6 in Windows.
The script:
var counter = 0;
function addGiftCard()
{
counter++;
$('cardCount').value=counter;
var newFields = $('GiftCard').cloneNode(true);
newFields.id = '';
newFields.style.display = 'block';
//alert("innerhtml = " + newFields.childNodes[1].innerHTML);
newFields.childNodes[1].id = "giftCardDesc" + (counter + 1 );
newFields.childNodes[1].innerHTML = "Gift Card " + (counter + 1) + " - Amount";
var newField = newFields.childNodes;
for (var i=0;i {
var theName = newField[i].name
if (theName)
newField[i].name = theName + counter;
}
var insertHere = document.getElementById('writeroot');
insertHere.parentNode.insertBefore(newFields,insertHere);
}
And here is the HTML:
Any ideas why this works on firefox and fails in IE?
Source: http://community.livejournal.com/javascript/103463.html