Jump to content

Script Working With Firefox, Not With Ie


nicolet

Recommended Posts

The following script behaves differently with Firefox and IE, both under Windows. With both browsers, clicking on a "Bit" changes it from 0 to 1 and back, but IE does not compute the decimal value (Firefox does). <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><title></title><meta http-equiv="Content-type" content="text/html; charset=iso-8859-1" /><script type="text/javascript" language="JavaScript"> var i = 0; j = 0; sum = 0; var b = new Array (0, 0, 0, 0, 0, 0, 0, 0); /* 0 or 1 */ function swap(id) { if (i==0) { document.getElementById(id).innerHTML = '1'; j = 1; b[id] = 1; } else { document.getElementById(id).innerHTML = '0'; j = 0; b[id] = 0; } i = j; document.getElementById('sum').textContent = b[0] + b[1]*2 + b[2]*4 + b[3]*8 + b[4]*16 + b[5]*32 + b[6]*64 + b[7]*128; }</script><style type="text/css"> td {width: 20px; height: 20px; text-align: center; } tr.bit td { font-size: 18px; border: 2px solid black; } tr.exp td { font-size: 14px; } td.dec, td#sum { width: 80px; color: blue; font-size: 14px; border: none; }</style></head><body><table summary=""><tr class="bit"><td id="7" onclick="swap(7);">0</td><td id="6" onclick="swap(6);">0</td><td id="5" onclick="swap(5);">0</td><td id="4" onclick="swap(4);">0</td><td id="3" onclick="swap(3);">0</td><td id="2" onclick="swap(2);">0</td><td id="1" onclick="swap(1);">0</td><td id="0" onclick="swap(0);">0</td><td id="sum">0</td></tr><tr class="exp"><td>2<sup>7</sup></td><td>2<sup>6</sup></td><td>2<sup>5</sup></td><td>2<sup>4</sup></td><td>2<sup>3</sup></td><td>2<sup>2</sup></td><td>2<sup>1</sup></td><td>2<sup>0</sup></td><td class="dec">decimal</td></tr></table></body></html>

Link to comment
Share on other sites

First thing to try is using a strict doctype instead of transitional. Unless you need a feature of transitional, that is, but most of the time, strict is best. You'll get best cross browser compliance.

Link to comment
Share on other sites

First thing to try is using a strict doctype instead of transitional. Unless you need a feature of transitional, that is, but most of the time, strict is best. You'll get best cross browser compliance.
Thank you for your suggestion. I'll try.François
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...