View Full Version : IE = Insane javascript, or insane coder ?

12-18-2005, 06:36 AM
First post here.. finally found a problem crazy enough to seek help :)
Here's the code:
for (i = 0; i < staffCnt; i++) {
if (i > staffNo) {
//Get this users details.
staffCB = document.getElementById('member_'+(i.toString()));
staffTR = document.getElementById('membertr_'+(i.toString()));
staffTD = document.getElementById('membertd_'+(i.toString()));
newID = (i - 1); //The new ID.

//Fix the ids/names/events.
staffCB.setAttribute('name', 'member_'+newID);
staffCB.setAttribute('id', 'member_'+newID);
staffTR.setAttribute('id', 'membertr_'+newID);
staffTD.setAttribute('id', 'membertd_'+newID);
It is working perfectly (although has been mangled a bit for testing purposes) on all browsers apart from IE.

Here's a rundown on what it's doing.
The point of this loop is to update remaining staff members after another has been removed.
staffCnt = The number of staff members (decremented after loop)
staffNo = The staff ID of the removed staff member.
staffCB = The staff members checkbox, has an onclick event handler that will call the function containing this loop.
staffTR/TD = Containers for the info.

Basically each time a staff member is removed it needs to update the IDs of later staff members.

The problem:
On IE the first removal works fine.
The second removal is where the crazyness begins.
It will update the first staff member no problems.
Somehow the second time staffCB = document.getElementById('member_'+(i.toString())); will return member_0.. and increment it by 1.
Then somehow the third time it will return member_2 and not increment it?

Heres a little snip I took when I had a ton of alerts in:
Other browsers:
0 - Skip, already removed.
1 - Set member_1 to member_0
2 - Set member_2 to member_1
3 - etc. etc.

0 - Skip already removed
1 - Set member_1 to member_0
2 - Set member_0 to member_1 ... WHAT THE?
3 - Set member_2 to member_2

Either my code is really messed up, or IE just wants me to explode.

Any ideas?

Thanks in advance :)