JavaScript and client side scripting.
Moderator: General Moderators
sarris
Forum Contributor
Posts: 137 Joined: Mon Dec 04, 2006 2:44 pm
Post
by sarris » Fri Apr 13, 2007 8:10 am
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?
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Fri Apr 13, 2007 6:55 pm
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 » Sat Apr 14, 2007 2:12 am
Are you getting any Javascript errors in the browser?
no...however i never did
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Sat Apr 14, 2007 10:08 am
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 » Sat Apr 14, 2007 2:54 pm
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
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Sat Apr 14, 2007 4:14 pm
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 » Sun Apr 15, 2007 12:06 pm
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
tecktalkcm0391
DevNet Resident
Posts: 1030 Joined: Fri May 26, 2006 9:25 am
Location: Florida
Post
by tecktalkcm0391 » Sun Apr 15, 2007 3:18 pm
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;
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Sun Apr 15, 2007 3:29 pm
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 » Mon Apr 16, 2007 9:18 am
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 » Wed Apr 18, 2007 12:42 am
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'+' €</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 » Wed Apr 18, 2007 9:05 am
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
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Wed Apr 18, 2007 10:29 am
Yup, you can thank Microsoft for their new standards compliant web browser.
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 » Thu Apr 19, 2007 6:56 am
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.