LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 11-30-2006, 10:02 AM   #1
stash1071
Member
 
Registered: Mar 2006
Distribution: Kubuntu 5.10
Posts: 35

Rep: Reputation: 15
JavaScript - IE vs Firefox - appending rows


Hey Everyone, was wondering if anyone could tell me why this code works in Firefox and not Internet Explorer. In IE, I just get "hello", in Firefox, I get the table and "hello". I have a feeling I'm missing something terribly obvious. Not exactly Linux but I know I'll get the best advice. Thanks!

<!DOCTYPE html PUBLIC "-//W3C//DTD html 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>My page</title>
</head>

<body>

<table id="myTable" border="1">
<tbody id="myTableBody">
</tbody>
</table>

<script type="text/javascript">

var cell = document.createElement("td").appendChild(document.createTextNode("foo"));
var row = document.createElement("tr").appendChild(cell);
var el = document.getElementById("myTableBody");

el.appendChild(row);

</script>

<h3>hello</h3>

</body>
</html>
 
Old 11-30-2006, 10:11 AM   #2
b0uncer
Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
I could guess IE is not following the standards, if you've written that according to them. Firefox might not follow the standards 100% either, but I've seen horrible acts from IE, so this is not big news it's just that a lot of people use IE, so a lot of people creating web sites don't care, which encourages IE developers to keep it that way. To sustain "compatibility"..heh.

Sorry that I can't be of too much help, I hope somebody else can. My java script learnings are quite minimal..
 
Old 11-30-2006, 10:24 AM   #3
stash1071
Member
 
Registered: Mar 2006
Distribution: Kubuntu 5.10
Posts: 35

Original Poster
Rep: Reputation: 15
What's especially frustrating about it is I've done this type of thing before. I've scaled back the page to simply follow an example from a book, Foundations of Ajax (of course no Ajax here_, titled "Appending Rows to a Table" in the Cross-Browser JavaScript chapter.
 
Old 11-30-2006, 11:04 AM   #4
stash1071
Member
 
Registered: Mar 2006
Distribution: Kubuntu 5.10
Posts: 35

Original Poster
Rep: Reputation: 15
I got it working breaking up the lines like so, I'll take it...

var cell = document.createElement("td");
var text = document.createTextNode("foox");

cell.appendChild(text);

var row = document.createElement("tr")
row.appendChild(cell);

var el = document.getElementById("myTableBody");
el.appendChild(row);
 
Old 11-30-2006, 11:16 AM   #5
vargadanis
Member
 
Registered: Sep 2006
Posts: 248

Rep: Reputation: 30
Works for me too in this way. What you might want to do is to create 2 versions of the same site: IE and Firefox. Both provide an awesome documentation.
http://developer.mozilla.org/en/docs/DOM
and
http://msdn.microsoft.com
You can find a AJAX tutorial on the Firefox AJAX site http://developer.mozilla.org/en/docs/AJAX that describes the differences. I love it. Good luck and let me know if you are done. (^_^)
 
  


Reply

Tags
ie, javascript


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ubuntu Edgy/Firefox 2/Javascript - Firefox closes accessing websites with Javascript Interdictor Ubuntu 8 11-02-2006 11:58 AM
Firefox Javascript Error socceroos Programming 1 03-15-2006 12:04 AM
javascript in firefox jackdoll Fedora 1 11-19-2005 02:18 AM
firefox no javascript windows TranceDude Linux - Software 8 09-10-2005 03:23 AM
javascript for firefox? mohapi Fedora 4 06-20-2004 03:22 PM


All times are GMT -5. The time now is 04:45 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration