M
Marc Bradshaw
Hi there, I'm fairly new to JavaScript, coming from a PHP background,
and I am using JavaScript to make the interface nicer on a customer
management system I developed. I'm currently working on the actual page
which allows users to edit a certain customer's details, but I am having
problems getting it to work in IE7.
I have a table containing names and contact details for customers. I
have a <tbody> tag after my <table> tag, and a </tbody> tag before my
</table> tag, which I thought meant that JavaScript in IE could then
work with the table. In any event, one of my JavaScript functions is
supposed to add two rows and then populate them.
The code is incredibly long so I have included a cut-down version below,
but here is a summary of how it works: I use createElement to produce
many <span> elements, four <td> elements and two <tr> elements. I then
use appendChild to place the <span> elements into the <td> elements, the
<td> elements into the <tr> elements, and the <tr> elements into my
existing <tbody>.
In Firefox this works fine. In IE, as soon as I click the button which
should execute the function, I get an 'error on page' message in the
Status bar. On clicking the icon, I get the error "Object doesn't
support this property or method" with this line:
contactsTable.appendChild(newContactTr1);. 'contactsTable' is my tbody,
which I get by using getElementById() on the previous line.
It's got me stumped. Does anyone have any ideas? The cut-down code is
pasted below.
Thanks,
Marc
this.insertContactDiv = function() {
var self = Contacts;
var fnameSpan = null;
var lnameSpan = null;
var fnameInput = null;
var lnameInput = null;
var cancelButton = null;
var saveButton = null;
var leftButtonDiv = null;
var rightButtonDiv = null;
var clearBothDiv = null;
fnameSpan = document.createElement('span');
lnameSpan = document.createElement('span');
fnameSpan.id = 'fname-NewContactTemp';
lnameSpan.id = 'lname-NewContactTemp';
newContactTr1 = document.createElement('tr');
newContactL1 = document.createElement('td');
newContactR1 = document.createElement('td');
newContactL1.style.fontWeight = 'bold';
newContactR1.style.fontWeight = 'bold';
space = function () { return document.createTextNode(' '); }
newContactTr1.id = 'row1-NewContactTemp';
newContactL1.appendChild(fnameSpan);
newContactL1.appendChild(space());
newContactL1.appendChild(lnameSpan);
newContactR1.appendChild(document.createTextNode('Address'));
newContactTr1.appendChild(newContactL1);
newContactTr1.appendChild(newContactR1);
contactsTable = document.getElementById('contactsTable');
contactsTable.appendChild(newContactTr1);
return true;
};
The applicable HTML being:
<tbody id="contactsTable">...</tbody>
and I am using JavaScript to make the interface nicer on a customer
management system I developed. I'm currently working on the actual page
which allows users to edit a certain customer's details, but I am having
problems getting it to work in IE7.
I have a table containing names and contact details for customers. I
have a <tbody> tag after my <table> tag, and a </tbody> tag before my
</table> tag, which I thought meant that JavaScript in IE could then
work with the table. In any event, one of my JavaScript functions is
supposed to add two rows and then populate them.
The code is incredibly long so I have included a cut-down version below,
but here is a summary of how it works: I use createElement to produce
many <span> elements, four <td> elements and two <tr> elements. I then
use appendChild to place the <span> elements into the <td> elements, the
<td> elements into the <tr> elements, and the <tr> elements into my
existing <tbody>.
In Firefox this works fine. In IE, as soon as I click the button which
should execute the function, I get an 'error on page' message in the
Status bar. On clicking the icon, I get the error "Object doesn't
support this property or method" with this line:
contactsTable.appendChild(newContactTr1);. 'contactsTable' is my tbody,
which I get by using getElementById() on the previous line.
It's got me stumped. Does anyone have any ideas? The cut-down code is
pasted below.
Thanks,
Marc
this.insertContactDiv = function() {
var self = Contacts;
var fnameSpan = null;
var lnameSpan = null;
var fnameInput = null;
var lnameInput = null;
var cancelButton = null;
var saveButton = null;
var leftButtonDiv = null;
var rightButtonDiv = null;
var clearBothDiv = null;
fnameSpan = document.createElement('span');
lnameSpan = document.createElement('span');
fnameSpan.id = 'fname-NewContactTemp';
lnameSpan.id = 'lname-NewContactTemp';
newContactTr1 = document.createElement('tr');
newContactL1 = document.createElement('td');
newContactR1 = document.createElement('td');
newContactL1.style.fontWeight = 'bold';
newContactR1.style.fontWeight = 'bold';
space = function () { return document.createTextNode(' '); }
newContactTr1.id = 'row1-NewContactTemp';
newContactL1.appendChild(fnameSpan);
newContactL1.appendChild(space());
newContactL1.appendChild(lnameSpan);
newContactR1.appendChild(document.createTextNode('Address'));
newContactTr1.appendChild(newContactL1);
newContactTr1.appendChild(newContactR1);
contactsTable = document.getElementById('contactsTable');
contactsTable.appendChild(newContactTr1);
return true;
};
The applicable HTML being:
<tbody id="contactsTable">...</tbody>