List Info

Thread: need help in generating table on the fly




need help in generating table on the fly
user name
2006-01-22 16:27:27
I want to make a table (widht=120) after i click a button
with javascript.
I want my table having 2 rows.
- 1st row: consist of 2 column (column 1 having 20 width,
and 100 for the
second column)
- 2nd row: consist of only 1 column with 120 width

Here's the script:

----------------------------------------------
<head>

<script language="javascript"
type="text/javascript">

function tb_generate() {
 var tableMessage = document.getElementById("tb");
 var rowMessageLength = tableMessage.rows.length ;
 var rowMessageLast = rowMessageLength;

 //Row 1
 var row1 = tableMessage.insertRow(rowMessageLast);
 var col1 = row1.insertCell(0);
 col1.style.height = 20;
 col1.style.width = 120;
 col1.style.textAlign = 'left';
 col1.style.verticalAlign = 'middle';
 col1.style.backgroundColor = '#FF0000';

 var col2 = row1.insertCell(1);
 //col2.setAttribute('colspan', 2);
 col2.style.height = 20;
 col2.style.width = 100;
 col2.style.textAlign = 'center';
 col2.style.verticalAlign = 'middle';
 col2.style.backgroundColor = '#FF00FF';

 //Row 2
 var row2 = tableMessage.insertRow(rowMessageLast+1);
 var col3 = row2.insertCell(0);
 col3.colspan = 2;
 col3.style.height = 20;
 col3.style.width = 120;
 col3.style.textAlign = 'left';
 col3.style.verticalAlign = 'middle';
 col3.style.backgroundColor = '#FFFF00';

}

</script>

</head>

<body>
<table width="120" border="0"
cellspacing="0" cellpadding="0"
id="tb">
</table>
<br><br>
<input type="button" id="button"
value="Click"
onClick="tb_generate();">
</body>
</html>
----------------------------------------------

The problem is, the 'colspan' in the second row seems not
working.
So the table width for each column still not displayed
properly as i wanted
to be.
Can anyone help me?

Thx in advance,
rendian


[Non-text portions of this message have been removed]



For a quick response, your message should include,
 
- A copy of the code
- A copy of any error messages
- A description of what you're trying to achieve
- A description of what's actually happening
http://www.trans4mind.com/personal_developmen
t/HTMLGuide/index.html  For HTML
http://www.trans4mind.com/personal_developme
nt/JavaScript/index.html For JavaScript
You can also download the JavaScript and HTML tutorials
(Nearly 2.5 megabytes.)
A 30 day version of jsEditor is available for free download
at
http://www.trans4mind.com/personal_devel
opment/JavaScript/freeEditor.htm
--------------------------
FREE zip/unzip program:
http://www.trans4mind.com/personal_development/z
ipper/index.html
--------------------------OR go to and change your settings:
http://g
roups.yahoo.com/group/1stJavaScript/
List owner:  1stJavaScript-owner@yahoogroups.com 


://groups.yahoo.com/group/1stJavaScript/
List owner:  1stJavaScript-owner@yahoogroups.com 


 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://g
roups.yahoo.com/group/1stJavaScript/

<*> To unsubscribe from this group, send an email to:
    1stJavaScript-unsubscribe@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.c
om/info/terms/
 


[1]

about | contact  Other archives ( Real Estate discussion Medical topics )