473,399 Members | 4,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

insert html code to createelement("td")

130 100+
hello all
i did this table useing
createElement();
i am trying to insert html code to the <td> to put img and links
but so far no luck
any one have an idea on how it shouled b done?
the second qustion is how i can desing the hieght of the td
here is snippet

Expand|Select|Wrap|Line Numbers
  1. var cell = document.createElement("td");            
  2. var cellText = document.createTextNode(only text ids display, no innerHTML?); 
  3. cell.setAttribute("aligen","center");        //dosent work         
  4. cell.appendChild(cellText);
  5. row.appendChild(cell);                                     
also my last qustion is how can i see the code that been generate?
i see that the table is there but i cant see the html codeof it soi cant copy paste it

thanks guys
Oct 28 '07 #1
6 19069
Ferris
101 100+
Hi

I tested your code,and I think the problem is you missed quote mark in your code,and you spell wrong.

change
var cellText = document.createTextNode(only text ids display, no innerHTML?);
into
var cellText = document.createTextNode("only text ids display, no innerHTML?");

change
cell.setAttribute("aligen","center");
into
cell.setAttribute("align","center");

then,you'll see the text in your table.

here is my test code:
[HTML]
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<table width="50%" border="1">
<tr id="tr1">

</tr>
</table>
</body>
</html>

<script language="javascript">
var row = document.getElementById("tr1");
var cell = document.createElement("td");
var cellText = document.createTextNode("only text ids display, no innerHTML?");
cell.setAttribute("align","center"); //now works
cell.appendChild(cellText);
row.appendChild(cell);
</script>

[/HTML]


for your 2th question:

since your table is created by javascript(DOM),you table is a part of javascript code in your HTML code. you can't find the HTML code after the table is created. You can using DOM Inspector in Firefox,or IE Develop Toolbar in IE to check your table was created successfully,or not.



hope it helps.
Oct 28 '07 #2
Amzul
130 100+
Hi

I tested your code,and I think the problem is you missed quote mark in your code,and you spell wrong.

change
var cellText = document.createTextNode(only text ids display, no innerHTML?);
into
var cellText = document.createTextNode("only text ids display, no innerHTML?");

change
cell.setAttribute("aligen","center");
into
cell.setAttribute("align","center");

then,you'll see the text in your table.

here is my test code:
[HTML]
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<table width="50%" border="1">
<tr id="tr1">

</tr>
</table>
</body>
</html>

<script language="javascript">
var row = document.getElementById("tr1");
var cell = document.createElement("td");
var cellText = document.createTextNode("only text ids display, no innerHTML?");
cell.setAttribute("align","center"); //now works
cell.appendChild(cellText);
row.appendChild(cell);
</script>

[/HTML]


for your 2th question:

since your table is created by javascript(DOM),you table is a part of javascript code in your HTML code. you can't find the HTML code after the table is created. You can using DOM Inspector in Firefox,or IE Develop Toolbar in IE to check your table was created successfully,or not.



hope it helps.
thanks man, you were right about my bad spelling :/

but for the first qustion i think i havent explain myself good.
i know i need to put ""in the () but i want to use html code
like that :

Expand|Select|Wrap|Line Numbers
  1. var code="<a href=\"www.thescripts.com\">the scipts</a>"
  2. var cellText = document.createTextNode(code); // i want to put the link (code) in the <td> 
about the 3 Qustion,
is there a way to take the all code and insert it to a var and not just for <tag>
i need to display the code as well not just the table

hope u can understand me
Oct 28 '07 #3
Ferris
101 100+
Hi:

Oh,I see. you want to insert HTML code into <td> HTML is not a textNode,so you can't insert it using createTextNode. but , you can do it like this:

Expand|Select|Wrap|Line Numbers
  1.     var cell = document.createElement("td");
  2.     var code = "<a href=\"www.thescripts.com\">the scipts</a>";
  3.     cell.setAttribute("align","center"); 
  4.     cell.innerHTML = code;
  5.     row.appendChild(cell);
  6.  

for your 3rd question,of cause you can insert all your code to a var. look at these code:

Expand|Select|Wrap|Line Numbers
  1.     var code= "<a href=\"http://www.thescripts.com\">the scipts</a>";
  2.     document.write(code);
  3.  
also,you can use innerHTML to insert your code.


Expand|Select|Wrap|Line Numbers
  1.     var code= "<a href=\"http://www.thescripts.com\">the scipts</a>";
  2.     document.getElementsByTagName("body")[0].innerHTML = code;
  3.  
am I clear?

hope it helps.
Oct 28 '07 #4
Amzul
130 100+
Hi:

Oh,I see. you want to insert HTML code into <td> HTML is not a textNode,so you can't insert it using createTextNode. but , you can do it like this:

Expand|Select|Wrap|Line Numbers
  1.     var cell = document.createElement("td");
  2.     var code = "<a href=\"www.thescripts.com\">the scipts</a>";
  3.     cell.setAttribute("align","center"); 
  4.     cell.innerHTML = code;
  5.     row.appendChild(cell);
  6.  

for your 3rd question,of cause you can insert all your code to a var. look at these code:

Expand|Select|Wrap|Line Numbers
  1.     var code= "<a href=\"http://www.thescripts.com\">the scipts</a>";
  2.     document.write(code);
  3.  
also,you can use innerHTML to insert your code.


Expand|Select|Wrap|Line Numbers
  1.     var code= "<a href=\"http://www.thescripts.com\">the scipts</a>";
  2.     document.getElementsByTagName("body")[0].innerHTML = code;
  3.  
am I clear?

hope it helps.
thanks. that help me alot
i am 90% from my goal.
but agian please explian how to insret the code that DOM generated to a var...
i not only need to show the table that DOM creted i alsoneed to show the code of it
is that posible?
i know i can do it all in inerrHTML but its not elegent and i woued have to write itall agian :\
Oct 28 '07 #5
acoder
16,027 Expert Mod 8TB
i not only need to show the table that DOM creted i alsoneed to show the code of it
You mean display it on the screen?
Oct 29 '07 #6
Amzul
130 100+
You mean display it on the screen?
i ment that i need to display the code that the DOM create

i mange to do so like this

Expand|Select|Wrap|Line Numbers
  1. //asumming that tblis the highr level of the tabl (father)
  2. generated_code=tbl.innerHTML;
now i can put it anyware i want (in a <pre> <div> etc...)
Oct 29 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: rkhurana | last post by:
Hi I am writing a JSF application that uses some third party charts. While I can see the chart but the javascript that is supposed to calla function to update chart periodically has a problem. It...
11
by: Marcus Otmarsen | last post by:
In my CSS stylesheet I can define e.g. A { FONT-WEIGHT: bold; FONT-SIZE: 16px; } and TD A { FONT-WEIGHT: bold; FONT-SIZE: 12px; } What is the difference for a HTML code like
2
by: querry | last post by:
Hi all, I am trying to change the background color of individual Table Cells using the javascript as follows. function changecolor(e) { var etarg; if (!ee) var ee = window.event; ...
1
by: msg2ajay | last post by:
hi, i am working on <div> i have to hide some part of the table. I am not able to hide that table part can anybady tell me where is the error. <html> <head> <script...
1
by: zaidalin79 | last post by:
I am in a JavaScript class, and we have to get all of our code to validate at the w3c website... Here is my code, it does what I want it to do which is require the user to enter the name and either...
2
by: hotflash | last post by:
Hi All, I found the best pure ASP code to upload a file to either server and/or MS Access Database. It works fine for me however, there is one thing that I don't like and have tried to fix but...
3
by: blackrunner | last post by:
ERROR in my Query?! ERROR: Element GESCHLECHT is undefined in FORM. i think everything ok. Maby somebody can help me here Element GESCHLECHT is undefined in FORM. The error occurred...
8
by: thatcollegeguy | last post by:
http://smarterfootball.com/exits/theHTML.html I am not sure what is wrong w/ this code. The main issue is that the table that is in the initial html will empty its td but the table that I load...
0
by: Akpo | last post by:
Hi all, i am writing an ajax and php application for a sec ondary school, and i want the contents of one select list to be based on the values of the select list that appears before it. The issue is...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.