Click to See Complete Forum and Search --> : Dynamic Form


mili
05-01-2003, 09:00 AM
I've been sitting on this problem for days and not able to find a solution for this. please can someone help me in this?
I have a table and I'm adding rows dynamically by hitting a "Add Row" button.My questions are:
1. How can I delete multiple rows at one shot by checking a check box (after adding the rows dynamically)
2. How can I store the values entered in these fields and post the form?
PS: I suck at JS and I'm still in the process of learning.
Thanks,
Here is my code:

<html>
<html>
<head>
<script language="JavaScript" type="text/javascript">
function addRow(id){
var tbody = document.getElementById
(id).getElementsByTagName("TBODY")[0];
var row = document.createElement("TR")
var td1 = document.createElement("TD")
td1.innerHTML = "<input type=text align=center size=25 name='"+name+"' id='"+name+"'>";
//td1.appendChild(document.createTextNode("column 1"))
var td2 = document.createElement("TD")
td2.innerHTML = "<input type=text align=center size=25 name='"+name+"' id='"+name+"'>";
//td2.appendChild (document.createTextNode("column 2"))
var td3 = document.createElement("TD")
td3.innerHTML = "<input type=text align=center size=25 name='"+name+"' id='"+name+"'>";
//td3.appendChild (document.createTextNode("column 2"))
row.appendChild(td1);
row.appendChild(td2);
row.appendChild(td3);
tbody.appendChild(row);
}

</script>
</head>
<body>
<table id="myTable" cellspacing="0" width="100%" border="1">
<tbody>
<tr bgcolor="#cfcfcf">
<td width="30%">column1</td><td width="30%">column2</td><td width="30%">column3<a href="javascript:addRow('myTable')">Add row</a></td>
</tr>
</tbody>
</table>
</body>
</html>

khalidali63
05-01-2003, 09:08 AM
This link should help you,only need to change it from radio button to check box.

http://68.145.35.86/skills/javascripts/DOMTableManipulation.html

Second,
create a form and then add rows and cells in that form,now you can add form fields in the cells and when you submit the form those fields will be passed on to the processing application.

beebob
05-01-2003, 09:28 AM
try this:

something with dynamic formfields (http://www.php-projekte.de/modules.php?name=ScriptParade&sp_action=show&show=1)

(click on scriptdemo ... below)

when you open the src there are functions at the bottom of the file that create such dyn. formfields.

bye,
beebob

mili
05-01-2003, 12:13 PM
Khalid,

Thanks for the information.But what I need is the check box being dynamically generated in every row and the ability to check each of these boxes or all of these and delete the rows.
Please can you suggest how this can be done?
Here is my code:
<html>
<html>
<head>
<script language="JavaScript" type="text/javascript">
function addRow(id){
var tbody = document.getElementById
(id).getElementsByTagName("TBODY")[0];
var row = document.createElement("TR")
var td1 = document.createElement("TD")
td1.innerHTML = "<input type=checkbox align=center name='"+name+"' id='"+name+"'>";
var td2 = document.createElement("TD")
td2.innerHTML = "<input type=text align=center size=25 name='"+name+"' id='"+name+"'>";
//td1.appendChild(document.createTextNode("column 1"))
var td3 = document.createElement("TD")
td3.innerHTML = "<input type=text align=center size=25 name='"+name+"' id='"+name+"'>";
//td2.appendChild (document.createTextNode("column 2"))
var td4 = document.createElement("TD")
td4.innerHTML = "<input type=text align=center size=25 name='"+name+"' id='"+name+"'>";
//td3.appendChild (document.createTextNode("column 2"))
row.appendChild(td1);
row.appendChild(td2);
row.appendChild(td3);
row.appendChild(td4);
tbody.appendChild(row);
}

</script>
</head>
<body>
<form name="Test">
<table id="myTable" cellspacing="0" width="100%" border="1">
<tbody>
<tr bgcolor="#cfcfcf">
<td width="10%"><input type="button" value="Delete"><input type="button" value="Add Row" onclick="addRow('myTable')"></td>
<td width="30%">column1</td>
<td width="30%">column2</td>
<td width="30%">column3</td>
</tr>
</tbody>
</table>
</form>




</body>
</html>

mili
05-02-2003, 09:40 AM
please can some one help me with this?

Thanks