createElement wont show table/div

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Mar 2005
Posts: 960
Reputation: belama is an unknown quantity at this point 
Solved Threads: 2
belama's Avatar
belama belama is offline Offline
Posting Shark

createElement wont show table/div

 
0
  #1
Apr 19th, 2005
I've come up with this code and cant figure out why nothing appears when I press the button. The table is soposed to show. Probably something really simple cuz I often stuck on stupid things.

[HTML]<html>
<head>
<script type="text/javascript">

function appendtable() {

var div = document.getElementById("divide");

var ControlsDesign = document.createElement("div");
var table_cd = document.createElement("table");
var tr_cd = document.createElement("tr");
var td_cd = document.createElement("td");
var table_content = document.createElement("table");

var tr = document.createElement("tr");
var td = document.createElement("td");
var t = document.createTextNode("Some text");

td.appendChild(t);
tr.appendChild(td);
table_content.appendChild(tr);

td_cd.appendChild(table_content);
tr_cd.appendChild(td_cd);
table_cd.appendChild(tr_cd);
ControlsDesign.appendChild(table_cd);

div.appendChild(ControlsDesign);

alert(document.getElementById("divide").innerHTML);
}


</script>
</head>
<body bgcolor="#999999">

<div id="divide" height="100"></div><input type="button" onclick="appendtable()" value="Press me">

</body>
</html>[/HTML]

Thanks for helping.
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 355
Reputation: DanceInstructor is an unknown quantity at this point 
Solved Threads: 14
DanceInstructor's Avatar
DanceInstructor DanceInstructor is offline Offline
Posting Whiz

Re: createElement wont show table/div

 
0
  #2
Apr 19th, 2005
You will be happy to know that this works in Firefox, but not in Internet Explorer. I'm not sure what the exact problem is, but it has something to do with the DOM and browser compatibility. If I figure it out I will let you know.
Clear Mind Hosting and Web Design

If I've helped you please consider adding to my reputation.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 960
Reputation: belama is an unknown quantity at this point 
Solved Threads: 2
belama's Avatar
belama belama is offline Offline
Posting Shark

Re: createElement wont show table/div

 
0
  #3
Apr 19th, 2005
That sucks. I really need it to work in IE. The weirdest thing is that the code is really there but wont show up on the page.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 960
Reputation: belama is an unknown quantity at this point 
Solved Threads: 2
belama's Avatar
belama belama is offline Offline
Posting Shark

Re: createElement wont show table/div

 
0
  #4
Apr 20th, 2005
I added this line of code at the end of the function.
[HTML]document.getElementById("divide").innerHTML = document.getElementById("divide").innerHTML;[/HTML]
The code existed so I just kind of refreshed it. If anything better comes up I will change it.
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 355
Reputation: DanceInstructor is an unknown quantity at this point 
Solved Threads: 14
DanceInstructor's Avatar
DanceInstructor DanceInstructor is offline Offline
Posting Whiz

Re: createElement wont show table/div

 
0
  #5
Apr 20th, 2005
Glad you got it working.
Clear Mind Hosting and Web Design

If I've helped you please consider adding to my reputation.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 1
Reputation: madhurao2684 is an unknown quantity at this point 
Solved Threads: 0
madhurao2684 madhurao2684 is offline Offline
Newbie Poster

Re: createElement wont show table/div

 
0
  #6
Mar 3rd, 2008
The problem is because of
var tr = document.createElement("tr");
var td = document.createElement("td");
In case of IE the above two lines of code doesn't work. Instead it should be
var tr = table.insertRow(<row index>);
var td = tr.insertCell(<cellIndex>);
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC