0

The following code works in all browser but IE8 and below.

            // Create Paragraph
            var para1 = document.createElement('p');
            var htmlstring = '<div style="width: 300px; font-family: "Lucida Grande", Helvetica, Arial, sans-serif; font-size: 6pt; color: #FF0000;">'
            htmlstring = htmlstring + '<table style="width: 300px; font-family: "Lucida Grande", Helvetica, Arial, sans-serif; font-size: 6pt; color: #FF0000;">'
            htmlstring = htmlstring + '<tr><td style="width: 100px;"><strong>ID</strong></td><td style="width: 200px;">' + ID + '</td></tr>';
            htmlstring = htmlstring + '<tr><td><strong>Date/Time</strong></td><td>' + DateStamp + '</td></tr>';
            htmlstring = htmlstring + '<tr><td><strong>Location</strong></td><td>' + Location + '</td></tr>';
            htmlstring = htmlstring + '<tr><td><strong>Event</strong></td><td>' + Event + '</td></tr>';
            htmlstring = htmlstring + '<tr><td><strong>Speed</strong></td><td>' + Speed + '</td></tr></table></div>';
            para1.innerHTML = htmlstring;  << THIS IS GENERATING AN UNKNOWN ERROR

Any one have a solution or know even why this is happening?

Thanks, Jim

  • 1
    How doesn't it work? (What is the error message.) You can access it via the warning icon in the status bar in IE. – J. K. Jun 22 '12 at 08:59
  • Do all of your used variables come out properly? Did you log and check the resulting String? – m90 Jun 22 '12 at 09:00
  • http://stackoverflow.com/questions/2946656/advantages-of-createelement-over-innerhtml – Simon Jun 22 '12 at 09:04
  • Remove `DIV` declaration from _htmlstring_. Or append `DIV` into `P` as `document.createElement("p").appendChild(document.createElement("div"))` – Andrew D. Jun 22 '12 at 09:25

1 Answers1

0

There is a lot of "problems" with innerHtml in IE8 and below, for example see this document.getElementById().innerHtml + IE7 can cause problems.

The most safe solution is probably to set innerHtml of a div instead of a paragraph.

Xharze
  • 2,703
  • 2
  • 17
  • 30
  • `p` is not listed in the set of elements who have a read-only `innerHTML` property: http://msdn.microsoft.com/en-us/library/ms533897(VS.85).aspx – Rob W Jun 22 '12 at 09:04
  • It works on all browsers bar IE8 and lower so it's not my variables or script – Jim Buckley Barret Jun 22 '12 at 13:04
  • Thanks Xharze, I changed the code to this; // Create Paragraph var para1 = document.createElement('p'); var adiv = document.createElement('div'); adiv.style.cssText = 'width: 300px; font-family: "Lucida Grande", Helvetica, Arial, sans-serif; font-size: 10pt; color: #000000;'; ... adiv.innerHTML = htmlstring; // para1.innerHTML = htmlstring; para1.appendChild(adiv); – Jim Buckley Barret Jun 22 '12 at 14:16