works on mozzila, not on IE7

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
sarris
Forum Contributor
Posts: 137
Joined: Mon Dec 04, 2006 2:44 pm

works on mozzila, not on IE7

Post by sarris »

hi there. came up to a werid problem
i have this code

Code: Select all

	houselist = document.getElementById("listdiv");
	var house = document.createElement("table");
        alert("1");
	var htmlstring = '<tr><td width = "180">'+address+'</td><td width = "110">Type</td><td align = "center" width = "85" rowspan = "2"><b>'+size+' sq.m</b></td><td align = "center" width = "85" rowspan = "2"><b>'+price+' €</b></td><td align = "center" width = "130" rowspan = "3">Image Here</td></tr><tr><td><strong>'+area+'</strong></td><td>'+beds+' rooms</td></tr><tr><td>id: '+id+'</td><td><a href="javascript: closerLook('+id+')"><small>Closer Look onMap</small></a></td></tr>';
         alert("2");
	house.innerHTML = htmlstring;
        alert("3");

on mozzila everything works ok
on IE7 alert 3 doesnt show...off course nothing else works after that.
anyone knows why?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Are you getting any Javascript errors in the browser?
sarris
Forum Contributor
Posts: 137
Joined: Mon Dec 04, 2006 2:44 pm

Post by sarris »

Are you getting any Javascript errors in the browser?
no...however i never did
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Maybe try something like:

Code: Select all

if (house.firstChild) {
    house.removeChild(house.firstChild);
}
house.appendChild(document.createTextNode(htmlstring));
Not saying it will work, but it might.
sarris
Forum Contributor
Posts: 137
Joined: Mon Dec 04, 2006 2:44 pm

Post by sarris »

i put your code and it went through alert 3 on IE7[/b, BUT

now in mozzila the html code is not recognised. Instead of having html elements created (as it is happening allright with previous code and mozzila) it shows just the string

Code: Select all

'<tr><td width = "180">'+address+'</td><td width = "120">Type</td><td align = "center" width = "85" rowspan = "2"><b>'+size+' sq.m</b></td><td align = "center" width = "85" rowspan = "2"><b>'+price+' €</b></td><td align = "center" width = "130" rowspan = "3">Image Here</td></tr><tr><td><strong>'+area+'</strong></td><td>'+beds+' rooms</td></tr><tr><td>id: '+id+'</td><td><a href="javascript: closerLook('+id+')"><small>Closer Look onMap</small></a></td></tr>';
on IE7 it shows on the bottom of the page "Page Error" AND it doesnt show any of the elements of house object

any more thoughts on it??
thanks allready though
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Does it show correctly in the alert prompt in Mozilla? How about Opera?
sarris
Forum Contributor
Posts: 137
Joined: Mon Dec 04, 2006 2:44 pm

Post by sarris »

with your code:
in both cases it shows the alerts.BUT
mozzila: show string instead of creating the rows and cells and indicated in the htmlstring
IE7: doesnt show anything, not rows and cells, nor string AND gives error in page and generally the siteresponds not well

with my code:
mozzila: everything works perfectly
IE7: runtime error at

Code: Select all

house.innerHTML = htmlstring
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

Why don't you try (dunno if it will work) this:

before the line now working put

Code: Select all

var house_html = document.getElementByTag("table"); 
// then go:
house_html.innerHTML = htmlstring; 
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I think its tagname, nut just tag. I think.
sarris
Forum Contributor
Posts: 137
Joined: Mon Dec 04, 2006 2:44 pm

Post by sarris »

Nope...didnt work with getElementByTag...
Must be cause i have so many tables on tha page. But still createElement returns the element it self. As long as it works with mozzila my code is ok. There must be a slight differation and its not working on IE7
ryan_mate
Forum Newbie
Posts: 2
Joined: Wed Apr 18, 2007 12:17 am

Post by ryan_mate »

You can't seem to set the innerHTML of a table element in IE.

A simple solution is: instead of trying to set the innerHTML to a string which contains the code for the table rows, you could just try adding a string with the entire code for the actual table, and add it to a div:

Code: Select all

var house = document.createElement("div");
var htmlstring = '<table><tr><td width = "180">'+'address'+'</td><td width = "110">Type</td><td align = "center" width = "85" rowspan = "2"><b>'+'size'+' sq.m</b></td><td align = "center" width = "85" rowspan = "2"><b>'+'price'+' &euro;</b></td><td align = "center" width = "130" rowspan = "3">Image Here</td></tr><tr><td><strong>'+'area'+'</strong></td><td>'+'beds'+' rooms</td></tr><tr><td>id: '+'id'+'</td><td><a href="javascript: closerLook('+'id'+')"><small>Closer Look onMap</small></a></td></tr></table>';
house.innerHTML = htmlstring;

Notice that the only change you need is to create a div rather than a table, and simply insert the the <table> </table> tags into your string.

Alternatively, use the DOM to create table rows and cells and add them programmatically.


- Ryan
sarris
Forum Contributor
Posts: 137
Joined: Mon Dec 04, 2006 2:44 pm

Post by sarris »

cool...worked with the div. i have problem with the setAttribute though...checked arroung the internet and many people have problems with IE7...it doesnt fully support many common functionalities...anyways thanks
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Yup, you can thank Microsoft for their new standards compliant web browser. :roll:

Sorry, I should not have used this as a means to bash Microsoft. But it was hard to resist.
sarris
Forum Contributor
Posts: 137
Joined: Mon Dec 04, 2006 2:44 pm

Post by sarris »

hahaha...dont worry. its giving me a hard time over and over again. i try to make something work, in the end i do and then i have to test it to stupid IE7 and always something is going wrong.
Post Reply