N
NoChat
Hi all --
I am new to arrays and could use some help. Here is my situation: I
have a very basic order form that I am allowing users to fill out.
They can enter multiple products onto this form, so I have created a
simple Javascript function that allows the user to dynamically add
another row of text boxes for each item he or she would like to
order. I am submitting the form to another ASP page which I hope can
read the information from the form and send an email notification to
somebody else.
I have already built the emailing portion of this ASP script, but I've
been unable to read in the various form items. I'm guessing there is
something incompatible with either my Javascript or ASP. I have
included the important code snippets below and could use some
assistance.
Thanks in advance!
--Ty
JAVASCRIPT & HTML CODE THAT CREATES DYNAMIC FORM OBJECTS
________________________________________________________
<script language="javascript">
row_no=1;
function addRow(tbl,row){
//so that user can only add 99 rows
if(row_no<=99){
var textbox1='<input type="text" name="pub[]">';//for text box
var textbox2='<input type="text" name="qty[]">';//for text box
var textbox3='<input type="text" name="comments[]">';//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>";
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 = textbox1;//insertion of the 'text'
variable in first cell
var newCell = newRow.insertCell(1);//second cell in the
row
newCell.innerHTML = textbox2;//insertion of the text box
and the remove text using their variable
var newCell = newRow.insertCell(2);//third cell in the row
newCell.innerHTML = textbox3;//insertion of the text box
and the remove text using their variable
var newCell = newRow.insertCell(3);//fourt cell in the row
newCell.innerHTML = remove;//insertion of the remove text
row_no++;
} catch (ex) {
alert(ex); //if exception occurs
}
}
if(row_no>99)//if the row contain 99 textboxes, the add button
will disapper
{
document.getElementById("add").style.display="none";
}
}
function removeRow(tbl,num)
{
var table = document.getElementById(tbl);//identification of table
try {
row_no--;
table.deleteRow(num);//deletion of the clicked row
} catch (ex) {
alert(ex);
}
if(row_no<=99)//if row is less than 3 then the button will again
appear to add row
{
document.getElementById("add").style.display="block";
}
}
</script>
<form id="orderForm" name="orderForm" method="post"
action="aspmail.asp">
<table width="700" border="0" cellpadding="0" cellspacing="0"
id="order">
<tr id="header">
<td width="190" valign="top" bgcolor="#666666"><strong>Pub
#</strong></td>
<td width="190" valign="top"
bgcolor="#666666"><strong>Quantity</strong></td>
<td width="190" valign="top"
bgcolor="#666666"><strong>Additional Comments</strong></td>
<td width="130" bgcolor="#666666"> </td>
</tr>
<tr id="item">
<td valign="top"><input type="text" name="pub"></td>
<td valign="top"><input type="text" name="qty"></td>
<td valign="top"><input type="text" name="comments"></td>
<td> </td>
</tr>
<tr id="footer">
<td colspan="4" valign="top"><input type="button" value="Add
another item" onClick="addRow('order','item')" ID="add"></td>
</tr>
<tr>
<td colspan="4" valign="top"><input type="submit" name="Submit"
id="Submit" value="Submit" /></td>
</tr>
</table>
</form>
________________________________________________________
ASP CODE I'M USING TO TRY AND READ IN THIS INFORMATION
________________________________________________________
Dim pub, qty, comments
'order information
pub = Array(Request.Form("pub"))
qty = Array(Request.Form("qty"))
comments = Array(Request.Form("comments"))
'* Pull in form arrays
For i=0 to ubound(pub)
Response.Write "Item #: " & pub(i) & "<br>" & vbCrLf
next
For i=0 to ubound(qty)
Response.Write "Qty #: " & qty(i) & "<br>" & vbCrLf
next
For i=0 to ubound(comments)
Response.Write "Comments: " & comments(i) & "<br>" & vbCrLf
next
I am new to arrays and could use some help. Here is my situation: I
have a very basic order form that I am allowing users to fill out.
They can enter multiple products onto this form, so I have created a
simple Javascript function that allows the user to dynamically add
another row of text boxes for each item he or she would like to
order. I am submitting the form to another ASP page which I hope can
read the information from the form and send an email notification to
somebody else.
I have already built the emailing portion of this ASP script, but I've
been unable to read in the various form items. I'm guessing there is
something incompatible with either my Javascript or ASP. I have
included the important code snippets below and could use some
assistance.
Thanks in advance!
--Ty
JAVASCRIPT & HTML CODE THAT CREATES DYNAMIC FORM OBJECTS
________________________________________________________
<script language="javascript">
row_no=1;
function addRow(tbl,row){
//so that user can only add 99 rows
if(row_no<=99){
var textbox1='<input type="text" name="pub[]">';//for text box
var textbox2='<input type="text" name="qty[]">';//for text box
var textbox3='<input type="text" name="comments[]">';//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>";
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 = textbox1;//insertion of the 'text'
variable in first cell
var newCell = newRow.insertCell(1);//second cell in the
row
newCell.innerHTML = textbox2;//insertion of the text box
and the remove text using their variable
var newCell = newRow.insertCell(2);//third cell in the row
newCell.innerHTML = textbox3;//insertion of the text box
and the remove text using their variable
var newCell = newRow.insertCell(3);//fourt cell in the row
newCell.innerHTML = remove;//insertion of the remove text
row_no++;
} catch (ex) {
alert(ex); //if exception occurs
}
}
if(row_no>99)//if the row contain 99 textboxes, the add button
will disapper
{
document.getElementById("add").style.display="none";
}
}
function removeRow(tbl,num)
{
var table = document.getElementById(tbl);//identification of table
try {
row_no--;
table.deleteRow(num);//deletion of the clicked row
} catch (ex) {
alert(ex);
}
if(row_no<=99)//if row is less than 3 then the button will again
appear to add row
{
document.getElementById("add").style.display="block";
}
}
</script>
<form id="orderForm" name="orderForm" method="post"
action="aspmail.asp">
<table width="700" border="0" cellpadding="0" cellspacing="0"
id="order">
<tr id="header">
<td width="190" valign="top" bgcolor="#666666"><strong>Pub
#</strong></td>
<td width="190" valign="top"
bgcolor="#666666"><strong>Quantity</strong></td>
<td width="190" valign="top"
bgcolor="#666666"><strong>Additional Comments</strong></td>
<td width="130" bgcolor="#666666"> </td>
</tr>
<tr id="item">
<td valign="top"><input type="text" name="pub"></td>
<td valign="top"><input type="text" name="qty"></td>
<td valign="top"><input type="text" name="comments"></td>
<td> </td>
</tr>
<tr id="footer">
<td colspan="4" valign="top"><input type="button" value="Add
another item" onClick="addRow('order','item')" ID="add"></td>
</tr>
<tr>
<td colspan="4" valign="top"><input type="submit" name="Submit"
id="Submit" value="Submit" /></td>
</tr>
</table>
</form>
________________________________________________________
ASP CODE I'M USING TO TRY AND READ IN THIS INFORMATION
________________________________________________________
Dim pub, qty, comments
'order information
pub = Array(Request.Form("pub"))
qty = Array(Request.Form("qty"))
comments = Array(Request.Form("comments"))
'* Pull in form arrays
For i=0 to ubound(pub)
Response.Write "Item #: " & pub(i) & "<br>" & vbCrLf
next
For i=0 to ubound(qty)
Response.Write "Qty #: " & qty(i) & "<br>" & vbCrLf
next
For i=0 to ubound(comments)
Response.Write "Comments: " & comments(i) & "<br>" & vbCrLf
next