User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 425,985 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,645 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 8178 | Replies: 5
Reply
Join Date: Mar 2005
Location: Ottawa, Ontario, Canada
Posts: 959
Reputation: belama is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 2
belama's Avatar
belama belama is offline Offline
Posting Shark

createElement wont show table/div

  #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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2005
Posts: 354
Reputation: DanceInstructor is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 12
DanceInstructor's Avatar
DanceInstructor DanceInstructor is offline Offline
Posting Whiz

Re: createElement wont show table/div

  #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  
Join Date: Mar 2005
Location: Ottawa, Ontario, Canada
Posts: 959
Reputation: belama is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 2
belama's Avatar
belama belama is offline Offline
Posting Shark

Re: createElement wont show table/div

  #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  
Join Date: Mar 2005
Location: Ottawa, Ontario, Canada
Posts: 959
Reputation: belama is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 2
belama's Avatar
belama belama is offline Offline
Posting Shark

Re: createElement wont show table/div

  #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  
Join Date: Feb 2005
Posts: 354
Reputation: DanceInstructor is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 12
DanceInstructor's Avatar
DanceInstructor DanceInstructor is offline Offline
Posting Whiz

Re: createElement wont show table/div

  #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  
Join Date: Mar 2008
Posts: 1
Reputation: madhurao2684 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
madhurao2684 madhurao2684 is offline Offline
Newbie Poster

Re: createElement wont show table/div

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 11:42 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC