Hello,
I'm new to Javascript, but I'm trying to create html tables based off a checkbox action. Is it possible to do this on the same page?
I've noticed that document.write() will create the tables in a new request which isn't what I'm looking for. I attempted to do this via DOM but I can't get the tables to show up in the page. -
function checkboxOnDemand(obj, parentId, childId, topHeader)
-
{
-
var checkbox = eval("document.checkForm." + obj.name);
-
-
if(checkbox.checked == true)
-
{
-
alert("Adding table");
-
addParentTable(parentId, childId, topHeader);
-
}
-
else
-
{
-
alert("Removing table");
-
removeElement(parentId, childId);
-
}
-
}
-
function addParentTable(parentId, childId, topHeader)
-
{
-
// get parent element (div)
-
var element = document.getElementById(parentId);
-
-
if(element != null)
-
{
-
// create parent table
-
var table = document.createElement('table');
-
table.setAttribute('name', childId);
-
-
// add style to table
-
var cssString = 'border:1px solid #000;width:600;left:800';
-
//table.style.cssText = cssString;
-
table.setAttribute('style',cssString);
-
-
// add table to parent
-
element.appendChild(table);
-
-
// create header row 1
-
var tr1 = document.createElement('tr');
-
var td1 = document.createElement('td');
-
-
table.appendChild(tr1);
-
tr1.appendChild(td1);
-
-
// add style to table data
-
var cssString1 = 'font-weight:bold;height:10';
-
//td.style.cssText = cssString1;
-
td1.setAttribute('style',cssString1);
-
-
//var text1 = document.createTextNode(topHeader);
-
//td.appendChild(text1);
-
-
for(var y = 1;y <= rowHeader.length;y++)
-
{
-
var tr = document.createElement('tr');
-
var td = document.createElement('td');
-
-
// add table elements
-
table.appendChild(tr);
-
tr.appendChild(td);
-
-
// add style to table data
-
var cssString = 'width:300';
-
//td.style.cssText = cssString;
-
td.setAttribute('style', cssString);
-
-
var div = document.createElement('div');
-
div.setAttribute('class', 'labelHeader');
-
-
var text2 = document.createTextNode(rowHeader[y-1]);
-
div.appendChild(text2);
-
-
var td2 = document.createElement('td');
-
var cssString2 = 'width:300';
-
//td2.style.cssText = cssString2;
-
td2.setAttribute('style', cssString2);
-
tr.appendChild(td2);
-
-
var textBox = document.createElement('input');
-
-
if(y == 3)
-
{
-
textBox.setAttribute('type', 'file');
-
-
// add "add more files" button here
-
var fileButton = document.createElement('input');
-
fileButton.setAttribute('type', 'button');
-
fileButton.setAttribute('href', '#');
-
fileButton.setAttribute('onClick', '\addAdditionalTable();\"');
-
}
-
else
-
{
-
textBox.setAttribute('type', 'text');
-
}
-
-
textBox.setAttribute('size', 30);
-
textBox.setAttribute('name', ('element' + y));
-
td2.appendChild(textBox);
-
}
-
-
/*var br1 = document.createElement('br');
-
var br2 = document.createElement('br');
-
element.appendChild(br1);
-
element.appendChild(br2);*/
-
}
-
}
-
-
<!-- JSP code that creates the checkboxes -->
-
<table height=100px width=300px>
-
<tr>
-
<td style="width:150"> <div class="labelHeader">Field Name:</div>
-
</td>
-
<td class="scroll" style="border:1px solid #000;width:200px; height:150px; overflow: auto">
-
<%
-
for(int x=1;x<=headers.length;x++)
-
{
-
out.println("<input type=\"checkbox\" onClick=\"checkboxOnDemand(this, \'tableSpace\', \'" + tables[x-1]
-
+ "\', \'" + headers[x-1] + "\');\" name=\"checkBox" + x + "\" />" + headers[x-1] + "<br>");
-
}%>
-
</td>
-
</tr>
-
</table>
2 2638
So this is your code
OK -
function checkboxOnDemand(obj, parentId, childId, topHeader)
-
{
-
var checkbox = eval("document.checkForm." + obj.name);
-
-
if(checkbox.checked == true)
-
{
-
alert("Adding table");
-
addParentTable(parentId, childId, topHeader);
-
}
-
else
-
{
-
alert("Removing table");
-
removeElement(parentId, childId);
-
}
-
}
-
function addParentTable(parentId, childId, topHeader)
-
{
-
// get parent element (div)
-
var element = document.getElementById(parentId);
-
-
if(element != null)
-
{
-
// create parent table
-
var table = document.createElement('table');
-
table.setAttribute('name', childId);
-
-
// add style to table
-
var cssString = 'border:1px solid #000;width:600;left:800';
-
//table.style.cssText = cssString;
-
table.setAttribute('style',cssString);
-
-
// add table to parent
-
element.appendChild(table);
-
-
// create header row 1
-
var tr1 = document.createElement('tr');
-
var td1 = document.createElement('td');
-
-
table.appendChild(tr1);
-
tr1.appendChild(td1);
-
-
// add style to table data
-
var cssString1 = 'font-weight:bold;height:10';
-
//td.style.cssText = cssString1;
-
td1.setAttribute('style',cssString1);
-
-
//var text1 = document.createTextNode(topHeader);
-
//td.appendChild(text1);
-
-
for(var y = 1;y <= rowHeader.length;y++)
-
{
-
var tr = document.createElement('tr');
-
var td = document.createElement('td');
-
-
// add table elements
-
table.appendChild(tr);
-
tr.appendChild(td);
-
-
// add style to table data
-
var cssString = 'width:300';
-
//td.style.cssText = cssString;
-
td.setAttribute('style', cssString);
-
-
var div = document.createElement('div');
-
div.setAttribute('class', 'labelHeader');
-
-
var text2 = document.createTextNode(rowHeader[y-1]);
-
div.appendChild(text2);
-
-
var td2 = document.createElement('td');
-
var cssString2 = 'width:300';
-
//td2.style.cssText = cssString2;
-
td2.setAttribute('style', cssString2);
-
tr.appendChild(td2);
-
-
var textBox = document.createElement('input');
-
-
if(y == 3)
-
{
-
textBox.setAttribute('type', 'file');
-
-
// add "add more files" button here
-
var fileButton = document.createElement('input');
-
fileButton.setAttribute('type', 'button');
-
fileButton.setAttribute('href', '#');
-
fileButton.setAttribute('onClick', '\addAdditionalTable();\"');
-
}
-
else
-
{
-
textBox.setAttribute('type', 'text');
-
}
-
-
textBox.setAttribute('size', 30);
-
textBox.setAttribute('name', ('element' + y));
-
td2.appendChild(textBox);
-
}
-
-
/*var br1 = document.createElement('br');
-
var br2 = document.createElement('br');
-
element.appendChild(br1);
-
element.appendChild(br2);*/
-
}
-
}
-
-
<!-- JSP code that creates the checkboxes -->
-
<table height=100px width=300px>
-
<tr>
-
<td style="width:150"> <div class="labelHeader">Field Name:</div>
-
</td>
-
<td class="scroll" style="border:1px solid #000;width:200px; height:150px; overflow: auto">
-
<%
-
for(int x=1;x<=headers.length;x++)
-
{
-
out.println("<input type=\"checkbox\" onClick=\"checkboxOnDemand(this, \'tableSpace\', \'" + tables[x-1]
-
+ "\', \'" + headers[x-1] + "\');\" name=\"checkBox" + x + "\" />" + headers[x-1] + "<br>");
-
}%>
-
</td>
-
</tr>
-
</table>
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Billy Cormic |
last post by:
Hello,
I am interested in dynamically creating temp tables using a
variable in MS SQL Server 2000.
For example:
DECLARE @l_personsUID int
select @l_personsUID = 9842
|
by: Craig Jurney |
last post by:
Am having difficulty creating a dynamic <select> element using direct
assignment to the element's option array (ie. someElement.option=new
Option(someText, someValue);)
that will work on Palm...
|
by: Stan Sainte-Rose |
last post by:
Hi,
I use this bit of code to generate dynamic tables in the page load section
....
Dim ntable as New Table
For i = 1993 To 2008
ntable = New Table
ntable.ID = "Q" + i.ToString
....
....
|
by: mht7 |
last post by:
I'm newbie to javascript and I did an extensive search on this site and couple of others looking for directions.
I'm attempting to write some custom javascript for collapsing the tables and fit it...
|
by: pukivruki |
last post by:
hi,
I wish to create a temporary table who's name is dynamic based on the
argument.
ALTER PROCEDURE .
@PID1 VARCHAR(50),
@PID2 VARCHAR(50),
@TICKET VARCHAR(20)
|
by: kpmassey |
last post by:
I'm using javascript to construct large tables from an array of data,
using ideas from:
http://www.oreillynet.com/pub/a/javascript/2003/05/06/dannygoodman.html
The data itself cannot be...
|
by: jkimbler |
last post by:
As part of our QA of hardware and firmware for the company I work for,
we need to automate some testing of devices and firmware. Since not
everybody here knows C#, I'm looking to create a new...
|
by: skyson2ye |
last post by:
Hi, guys:
I have written a piece of code which utilizes Javascript in PHP to create a three level dynamic list box(Country, States/Province, Market). However, I have encountered a strange problem,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |