Javascript Dynamic form field question
Hi,
I am using coldfusion 9 and I have a form with javascript in it that allows the user to create text boxes on the fly. It works well but I have no idea how I write it to a database. I have plenty of experience with writing form information to a db but not from dynamic fields. How do I do this when it is with dynamic fields in a primarily js form? My form code is below. Thank you very much.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Dynamic Page</title>
<script language="javascript">
row_no=1;
function addRow(tbl,row){
//so that user can only add 8 rows
if(row_no<=8){
var textbox='<input type="text" name="textfield[]">';//for text box
var remove= '<a href="#" onclick="removeRow(\''+ tbl +'\',\'' + row_no + '\')"/>Remove It</a>'; //for the text which is used to remove the current row by using the function removeRow(..,..)
//for suitable label to the row
if(row_no==1) text="<div class='label' align=right>First Textbox:</div>";
else if(row_no==2) text="<div class='label' align=right>Second Textbox:</div>";
else if(row_no==3) text="<div class='label' align=right>Third Textbox:</div>";
else if(row_no==4) text="<div class='label' align=right>Fourth Textbox:</div>";
else if(row_no==5) text="<div class='label' align=right>Fifth Textbox:</div>";
else if(row_no==6) text="<div class='label' align=right>Sixth Textbox:</div>";
else if(row_no==7) text="<div class='label' align=right>Seventh Textbox:</div>";
else if(row_no==8) text="<div class='label' align=right>Eighth Textbox:</div>";
var tbl = document.getElementById(tbl);//to identify the table in which the row will get insert
var rowIndex = document.getElementById(row).value;//to identify the row after which the row will be inserted
try {
var newRow = tbl.insertRow(row_no);//creation of new row
var newCell = newRow.insertCell(0);//first cell in the row
newCell.innerHTML = text;//insertion of the 'text' variable in first cell
var newCell = newRow.insertCell(1);//second cell in the row
newCell.innerHTML = textbox + " " + remove;//insertion of the text box and the remove text using their variable
row_no++;
} catch (ex) {
alert(ex); //if exception occurs
}
}
if(row_no>8)//if the row contain 3 textbox, the add button will disapper
{
document.getElementById("add").style.display="none";
}
}
function removeRow(tbl,num)
{
var table = document.getElementById(tbl);//adentification of table
try {
row_no--;
table.deleteRow(num);//deletion of the clicked row
} catch (ex) {
alert(ex);
}
if(row_no<=8)//if row is less than 8 then the button will again appear to add row
{
document.getElementById("add").style.display="block";
}
}
</script>
</head>
<body>
<form name="form1" method="post" action="">
<table width="450" border="0" cellspacing="0" cellpadding="0" id="mytable">
<tr id="myrow">
<td colspan="2" align="center"><h3>Dynamically Handeled Table</h3>
</td>
</tr>
<tr ID="add">
<td width="177"> </td>
<td width="273" align="right"><input type="button" name="Button" value="Add Text Box" onClick="addRow('mytable','myrow')"></td>
</tr>
<tr ID="add">
<td width="177"> </td>
<td width="273" align="right"> </td>
</tr>
</table>
</form>
</body>
</html>
