Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

loop thru dynamic form elements

Status
Not open for further replies.

bikebanditcom

Programmer
Jun 11, 2003
117
US
I have the following javascript, that as you can see dynamically generates two fields, i'll be adding two more fields that will be dependendent on the first two fields, i haven't worked out the dependendent drop downs, but i need to know how i can loop thru this code in vbscript on my take_sale.asp page, can anyone help? Thank you


<script language=&quot;JavaScript&quot;>
<!-- Dynamic Form
var recordCount = 0;
//start AddRow function block
function AddRow(){


var elemTbody, elemRow;
var elemCols = new Array(2);
var elemPackType, elemPackLevel

//create a reference to the tbody element in our table
elemTbody = document.getElementById(&quot;ResultTable&quot;).getElementsByTagName(&quot;tbody&quot;)[0];

//create the tr and td objects
elemRow = document.createElement(&quot;tr&quot;);
elemCols[0] = document.createElement(&quot;td&quot;);
elemCols[1] = document.createElement(&quot;td&quot;);



//create our text inputs and our select dropdown
elemPackType = document.createElement(&quot;select&quot;);
elemPackLevel = document.createElement(&quot;select&quot;);

var elemOption;
var elemOption2;

//do the select box next
elemPackType.name = &quot;packType_&quot; + recordCount;
elemPackType.size = &quot;1&quot;;

elemPackLevel.name = &quot;packLevel_&quot; + recordCount;
elemPackLevel.size = &quot;1&quot;;


//add the options
var optCtr;
// creating a new option: text, value


//add the option
elemOption = new Option(&quot;Select One&quot;,&quot;Select One&quot;);
elemPackType.add(elemOption);
elemOption = new Option(&quot;Type1&quot;,&quot;Type1&quot;);
elemPackType.add(elemOption);

elemOption2 = new Option(&quot;Select One&quot;,&quot;Select One&quot;);
elemPackLevel.add(elemOption2);
elemOption2 = new Option(&quot;Level1&quot;,&quot;Level1&quot;);
elemPackLevel.add(elemOption2);


//add the inputs to the appropriate cells
elemCols[0].appendChild(elemPackType);
elemCols[1].appendChild(elemPackLevel);



//add the cols to the row
elemRow.appendChild(elemCols[0]);
elemRow.appendChild(elemCols[1]);


//add the row to the tbody tag
elemTbody.appendChild(elemRow);

//increment recordCount and update hdnRecordCount input
recordCount++;
document.getElementById(&quot;recCount&quot;).value = recordCount;

}
// end of AddRow function block
//End Dynamic Form
//-->
</script>
 
if you response.write the javascript you can loop through it or if you want to loop it x number of times you could at at the begining
<%for n= 1 to x%>
then your javascript
<%next%>

or

<%if n < x then%>
then your javascript
n = n+1
<%end if%>
 
and rename n to whatever? im confused really about how to do that, im a novice

heres the new javascript, and one other thing, am i able to dynamically generate the element options,



<script language=&quot;JavaScript&quot;>
<!-- Dynamic Form
var recordCount = 0;
//start AddRow function block
function AddRow(){


var elemTbody, elemRow;
var elemCols = new Array(4);
var elemPackType, elemPackLevel, elemp_kbAmnt, elemp_pbcAmnt
//create a reference to the tbody element in our table
elemTbody = document.getElementById(&quot;ResultTable&quot;).getElementsByTagName(&quot;tbody&quot;)[0];

//create the tr and td objects
elemRow = document.createElement(&quot;tr&quot;);
elemCols[0] = document.createElement(&quot;td&quot;);
elemCols[1] = document.createElement(&quot;td&quot;);
elemCols[3] = document.createElement(&quot;td&quot;);
elemCols[4] = document.createElement(&quot;td&quot;);



//create our text inputs and our select dropdown
elemPackType = document.createElement(&quot;select&quot;);
elemPackLevel = document.createElement(&quot;select&quot;);
elemp_kbAmnt = document.createElement(&quot;input&quot;);
elemp_pbcAmnt = document.createElement(&quot;input&quot;);



//do the select box
elemPackType.name = &quot;packType_&quot; + recordCount;
elemPackType.size = &quot;1&quot;;

elemPackLevel.name = &quot;packLevel_&quot; + recordCount;
elemPackLevel.size = &quot;1&quot;;

//do the text boxs next
elemp_kbAmnt.name = &quot;p_kbAmnt_&quot; + recordCount;
elemp_kbAmnt.type = &quot;text&quot;;
elemp_kbAmnt.size = &quot;10&quot;;

elemp_pbcAmnt.name = &quot;p_pbcAmnt_&quot; + recordCount;
elemp_pbcAmnt.type = &quot;text&quot;;
elemp_pbcAmnt.size = &quot;10&quot;;

//add the options
var optCtr;
// creating a new option: text, value

var elemOption;
var elemOption2;

//add the option
elemOption = new Option(&quot;Select One&quot;,&quot;Select One&quot;);
elemPackType.add(elemOption);

elemOption2 = new Option(&quot;Select One&quot;,&quot;Select One&quot;);
elemPackLevel.add(elemOption2);


//add the inputs to the appropriate cells
elemCols[0].appendChild(elemPackType);
elemCols[1].appendChild(elemPackLevel);
elemCols[3].appendChild(elemp_kbAmnt);
elemCols[4].appendChild(elemp_pbcAmnt);

//add the cols to the row
elemRow.appendChild(elemCols[0]);
elemRow.appendChild(elemCols[1]);
elemRow.appendChild(elemCols[3]);
elemRow.appendChild(elemCols[4]);

//add the row to the tbody tag
elemTbody.appendChild(elemRow);

//increment recordCount and update hdnRecordCount input
recordCount++;
document.getElementById(&quot;recCount&quot;).value = recordCount;

}
// end of AddRow function block
//End Dynamic Form
//-->
</script>
 
You want to loop thru all the table objects that you created dinamicaly?
You want to be in vbscript? or JS is ok also.

________
George, M
 
i would prefer it be in vbscript as i know that better, let me post the entire page to you,

here are two pages, the salesEntry.asp page, and the take_Sale.asp page

salesEntry.asp

<%@LANGUAGE=&quot;VBSCRIPT&quot; %>
<!--#include file=&quot;Connections/pbcDB.asp&quot; -->
<%
Dim ProjectName
Dim ProjectName_numRows

Set ProjectName = Server.CreateObject(&quot;ADODB.Recordset&quot;)
ProjectName.ActiveConnection = MM_pbcDB_STRING
ProjectName.Source = &quot;SELECT projectName FROM tblProjects ORDER BY projectName ASC&quot;
ProjectName.CursorType = 0
ProjectName.CursorLocation = 2
ProjectName.LockType = 1
ProjectName.Open()

ProjectName_numRows = 0
%>
<%
Dim Salesmen
Dim Salesmen_numRows

Set Salesmen = Server.CreateObject(&quot;ADODB.Recordset&quot;)
Salesmen.ActiveConnection = MM_pbcDB_STRING
Salesmen.Source = &quot;SELECT salesmanName FROM tblSalesmen ORDER BY salesmanName ASC&quot;
Salesmen.CursorType = 0
Salesmen.CursorLocation = 2
Salesmen.LockType = 1
Salesmen.Open()

Salesmen_numRows = 0
%>
<%
Dim p_packages
Dim p_packages_numRows

Set p_packages = Server.CreateObject(&quot;ADODB.Recordset&quot;)
p_packages.ActiveConnection = MM_pbcDB_STRING
p_packages.Source = &quot;SELECT packageName FROM tblPackages ORDER BY packageName ASC&quot;
p_packages.CursorType = 0
p_packages.CursorLocation = 2
p_packages.LockType = 1
p_packages.Open()

p_packages_numRows = 0
%>
<%
Dim packageType
Dim packageType_numRows

Set packageType = Server.CreateObject(&quot;ADODB.Recordset&quot;)
packageType.ActiveConnection = MM_pbcDB_STRING
packageType.Source = &quot;SELECT packTypeName FROM tblPackageType ORDER BY packTypeName ASC&quot;
packageType.CursorType = 0
packageType.CursorLocation = 2
packageType.LockType = 1
packageType.Open()

packageType_numRows = 0
%>
<html>
<head>
<title>Sales Entry</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
<link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;style.css&quot;>
<script language=&quot;JavaScript&quot;>
<!-- Dynamic Form
var recordCount = 0;
//start AddRow function block
function AddRow(){


var elemTbody, elemRow;
var elemCols = new Array(4);
var elemPackType, elemPackLevel, elemp_kbAmnt, elemp_pbcAmnt
//create a reference to the tbody element in our table
elemTbody = document.getElementById(&quot;ResultTable&quot;).getElementsByTagName(&quot;tbody&quot;)[0];

//create the tr and td objects
elemRow = document.createElement(&quot;tr&quot;);
elemCols[0] = document.createElement(&quot;td&quot;);
elemCols[1] = document.createElement(&quot;td&quot;);
elemCols[3] = document.createElement(&quot;td&quot;);
elemCols[4] = document.createElement(&quot;td&quot;);



//create our text inputs and our select dropdown
elemPackType = document.createElement(&quot;select&quot;);
elemPackLevel = document.createElement(&quot;select&quot;);
elemp_kbAmnt = document.createElement(&quot;input&quot;);
elemp_pbcAmnt = document.createElement(&quot;input&quot;);



//do the select box
elemPackType.name = &quot;packType_&quot; + recordCount;
elemPackType.size = &quot;1&quot;;

elemPackLevel.name = &quot;packLevel_&quot; + recordCount;
elemPackLevel.size = &quot;1&quot;;

//do the text boxs next
elemp_kbAmnt.name = &quot;p_kbAmnt_&quot; + recordCount;
elemp_kbAmnt.type = &quot;text&quot;;
elemp_kbAmnt.size = &quot;10&quot;;

elemp_pbcAmnt.name = &quot;p_pbcAmnt_&quot; + recordCount;
elemp_pbcAmnt.type = &quot;text&quot;;
elemp_pbcAmnt.size = &quot;10&quot;;

//add the options
var optCtr;
// creating a new option: text, value

var elemOption;
var elemOption2;

//add the option
elemOption = new Option(&quot;Select One&quot;,&quot;Select One&quot;);
elemPackType.add(elemOption);

elemOption2 = new Option(&quot;Select One&quot;,&quot;Select One&quot;);
elemPackLevel.add(elemOption2);


//add the inputs to the appropriate cells
elemCols[0].appendChild(elemPackType);
elemCols[1].appendChild(elemPackLevel);
elemCols[3].appendChild(elemp_kbAmnt);
elemCols[4].appendChild(elemp_pbcAmnt);

//add the cols to the row
elemRow.appendChild(elemCols[0]);
elemRow.appendChild(elemCols[1]);
elemRow.appendChild(elemCols[3]);
elemRow.appendChild(elemCols[4]);

//add the row to the tbody tag
elemTbody.appendChild(elemRow);

//increment recordCount and update hdnRecordCount input
recordCount++;
document.getElementById(&quot;recCount&quot;).value = recordCount;

}
// end of AddRow function block
//End Dynamic Form
//-->
</script>
<link href=&quot;css/style.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;>
</head><body>
<h1>Sales Entry</h1>
<p><font size=&quot;2&quot;>Today Is <%= Now %>
</font></p>
<font face=&quot;Arial, Helvetica, sans-serif&quot;>
</font>
<form action=&quot;take_sale.asp&quot; method=&quot;post&quot; name=&quot;saleEntry&quot; id=&quot;saleEntry&quot; >
<table width=&quot;307&quot; cellpadding=&quot;2&quot; cellspacing=&quot;0&quot;>
<!--DWLayoutTable-->
<tr>
<td height=&quot;28&quot; colspan=&quot;2&quot; valign=&quot;top&quot;><p><font size=&quot;4&quot;><strong>Sale
Info</strong></font></p>
<hr>
</td>
<td width=&quot;2&quot;></td>
</tr>
<tr>
<td width=&quot;139&quot; height=&quot;30&quot; valign=&quot;top&quot;> <p><font size=&quot;2&quot;>Salesman: </font></p></td>
<td width=&quot;156&quot; valign=&quot;middle&quot;><font size=&quot;2&quot;>
<select name=&quot;p_salesman&quot; id=&quot;p_salesman&quot;>
<option selected value=&quot;&quot;>Select One</option>
<%
While (NOT Salesmen.EOF)
%>
<option value=&quot;<%=(Salesmen.Fields.Item(&quot;salesmanName&quot;).Value)%>&quot;><%=(Salesmen.Fields.Item(&quot;salesmanName&quot;).Value)%></option>
<%
Salesmen.MoveNext()
Wend
If (Salesmen.CursorType > 0) Then
Salesmen.MoveFirst
Else
Salesmen.Requery
End If
%>
</select>
</font></td>
<td></td>
</tr>
<tr>
<td height=&quot;34&quot; valign=&quot;middle&quot;><font size=&quot;2&quot;>Sale Date: </font></td>
<td valign=&quot;middle&quot;> <font size=&quot;2&quot;>
<input name=&quot;p_saleDate&quot; type=&quot;text&quot; id=&quot;p_saleDate&quot; value=&quot;<%= Date %>&quot; size=&quot;8&quot;>
</font></td>
<td></td>
</tr>
<tr>
<td height=&quot;34&quot; valign=&quot;middle&quot;><font size=&quot;2&quot;>Project Name: </font></td>
<td valign=&quot;middle&quot;><font size=&quot;2&quot;>
<select name=&quot;p_projectName&quot; id=&quot;p_projectName&quot;>
<option value=&quot;&quot;>Select One</option>
<%
While (NOT ProjectName.EOF)
%>
<option value=&quot;<%=(ProjectName.Fields.Item(&quot;projectName&quot;).Value)%>&quot;><%=(ProjectName.Fields.Item(&quot;projectName&quot;).Value)%></option>
<%
ProjectName.MoveNext()
Wend
If (ProjectName.CursorType > 0) Then
ProjectName.MoveFirst
Else
ProjectName.Requery
End If
%>
</select>
</font></td>
<td></td>
</tr>
<tr>
<td height=&quot;34&quot; valign=&quot;middle&quot;><font size=&quot;2&quot;>Lot Number: </font></td>
<td valign=&quot;middle&quot;><font size=&quot;2&quot;>
<input name=&quot;p_lotNum&quot; type=&quot;text&quot; id=&quot;p_lotNum&quot; size=&quot;10&quot;>
</font></td>
<td></td>
</tr>
<tr>
<td height=&quot;34&quot; valign=&quot;middle&quot;><font size=&quot;2&quot;>Release/Phase Num:</font></td>
<td valign=&quot;middle&quot;><font size=&quot;2&quot;>
<input name=&quot;p_phase&quot; type=&quot;text&quot; id=&quot;p_phase&quot; size=&quot;10&quot;>
</font></td>
<td></td>
</tr>
<tr>
<td height=&quot;34&quot; valign=&quot;middle&quot;><font size=&quot;2&quot; face=&quot;Arial, Helvetica, sans-serif&quot;>Customer
Name:</font></td>
<td valign=&quot;middle&quot;><font size=&quot;2&quot;>
<input name=&quot;p_customer&quot; type=&quot;text&quot; id=&quot;p_customer&quot; size=&quot;20&quot;>
</font></td>
<td></td>
</tr>
<tr>
<td height=&quot;8&quot;></td>
<td></td>
<td></td>
</tr>
</table>
<table width=&quot;451&quot;>
<!--DWLayoutTable-->
<tr>
<td height=&quot;63&quot; colspan=&quot;3&quot; valign=&quot;top&quot;><h3><strong>Package Info</strong></h3>
<hr> </td>
<td width=&quot;78&quot;>&nbsp;</td>
<td width=&quot;72&quot;>&nbsp;</td>
</tr>
<tr>
<td width=&quot;90&quot; height=&quot;34&quot; valign=&quot;middle&quot;> <p><font size=&quot;2&quot;>Package Type</font></p></td>
<td width=&quot;107&quot; valign=&quot;middle&quot;><font size=&quot;2&quot;>Package Level</font></td>
<td width=&quot;69&quot; valign=&quot;middle&quot;><font size=&quot;2&quot;>KB Amount</font></td>
<td valign=&quot;middle&quot;><font size=&quot;2&quot;>PBC Amount</font></td>
<td>&nbsp;</td>
</tr>
<tr>
<td height=&quot;37&quot; valign=&quot;middle&quot;><font size=&quot;2&quot;>
<select name=&quot;p_packType&quot; id=&quot;p_packType&quot;>
<option value=&quot;Select One&quot;>Select One</option>
<%
While (NOT packageType.EOF)
%>
<option value=&quot;<%=(packageType.Fields.Item(&quot;packTypeName&quot;).Value)%>&quot;><%=(packageType.Fields.Item(&quot;packTypeName&quot;).Value)%></option>
<%
packageType.MoveNext()
Wend
If (packageType.CursorType > 0) Then
packageType.MoveFirst
Else
packageType.Requery
End If
%>
</select>
</font> </td>
<td valign=&quot;middle&quot;><font size=&quot;2&quot;>
<select name=&quot;p_PackLevel&quot; id=&quot;p_PackLevel&quot;>
<option value=&quot;Select One&quot;>Select One</option>
<%
While (NOT p_packages.EOF)
%>
<option value=&quot;<%=(p_packages.Fields.Item(&quot;packageName&quot;).Value)%>&quot;><%=(p_packages.Fields.Item(&quot;packageName&quot;).Value)%></option>
<%
p_packages.MoveNext()
Wend
If (p_packages.CursorType > 0) Then
p_packages.MoveFirst
Else
p_packages.Requery
End If
%>
</select>
</font> <font size=&quot;2&quot;>&nbsp; </font> </td>
<td valign=&quot;middle&quot;><font size=&quot;2&quot;>
<input name=&quot;p_kbAmnt&quot; type=&quot;text&quot; id=&quot;p_kbAmnt&quot; size=&quot;10&quot;>
</font></td>
<td valign=&quot;middle&quot;><font size=&quot;2&quot;>
<input name=&quot;p_pbcAmnt&quot; type=&quot;text&quot; id=&quot;pbcAmnt&quot; size=&quot;10&quot;>
</font></td>
<td></td>
</tr>
<tr>
<td height=&quot;3&quot;></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
<table id=&quot;ResultTable&quot;>
<!--DWLayoutTable-->
<tr>
</tr>
<tbody>
</tbody>
<tr>
<td colspan=&quot;3&quot; align=&quot;center&quot;> <input type=&quot;button&quot; value=&quot;Add a Package&quot; onClick=&quot;AddRow();&quot;>
</td>
</tr>
</table>
<table width=&quot;313&quot; border=&quot;0&quot;>
<!--DWLayoutTable-->
<tr>
<td width=&quot;106&quot; height=&quot;34&quot; valign=&quot;middle&quot;><font size=&quot;2&quot; face=&quot;Arial, Helvetica, sans-serif&quot;>KB
Amount</font></td>
<td width=&quot;197&quot; valign=&quot;middle&quot;> <font size=&quot;2&quot;>
<input name=&quot;p_kbAmntCalc&quot; type=&quot;text&quot; id=&quot;p_kbAmntCalc&quot; size=&quot;10&quot;>
</font></td>
</tr>
<tr>
<td height=&quot;34&quot; valign=&quot;middle&quot;><font size=&quot;2&quot; face=&quot;Arial, Helvetica, sans-serif&quot;>PBC
Amount</font></td>
<td valign=&quot;middle&quot;><font size=&quot;2&quot;>
<input name=&quot;p_pbcAmntCalc&quot; type=&quot;text&quot; id=&quot;p_pbcAmntCalc&quot; size=&quot;10&quot;>
</font></td>
</tr>
</table>
<p>
<input type=&quot;hidden&quot; name=&quot;hdnRecordCount&quot; id=&quot;RecCount&quot; value=&quot;0&quot;>
<input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Submit Sale&quot;>
</p>
</form>
</body>
</html>
<%
ProjectName.Close()
Set ProjectName = Nothing
%>
<%
Salesmen.Close()
Set Salesmen = Nothing
%>
<%
p_packages.Close()
Set p_packages = Nothing
%>
<%
packageType.Close()
Set packageType = Nothing
%>


take_sale.asp

<%@LANGUAGE=&quot;VBSCRIPT&quot; CODEPAGE=&quot;1252&quot;%>
<%

p_salesman = Request.form(&quot;p_salesman&quot;)
p_saleDate = Request.form(&quot;p_saleDate&quot;)
p_projectName = Request.form(&quot;p_projectName&quot;)
p_lotNum = Request.form(&quot;p_lotNum&quot;)
p_phase = Request.form(&quot;p_phase&quot;)
p_customer = Request.form(&quot;p_customer&quot;)
p_packType = Request.form(&quot;p_packType&quot;)
p_PackLevel = Request.form(&quot;p_PackLevel&quot;)
p_kbAmnt = Request.form(&quot;p_kbAmnt&quot;)
p_pbcAmnt = Request.form(&quot;p_pbcAmnt&quot;)
p_kbAmntCalc = Request.form(&quot;p_kbAmntCalc&quot;)
p_pbcAmntCalc = Request.form(&quot;p_pbcAmntCalc&quot;)

set pbcDB = server.createObject(&quot;ADODB.Connection&quot;)
pbcDB.open &quot;pbc&quot;

theSQL = &quot;insert into tblSales (p_salesman, p_saleDate, p_projectName, p_lotNum, p_phase, p_customer) values ('&quot;&p_salesman&&quot;', '&quot;&p_saleDate&&quot;', '&quot;&p_projectName&&quot;', '&quot;&p_lotNum&&quot;', '&quot;&p_phase&&quot;', '&quot;&p_customer&&quot;') &quot;

pbcDB.Execute(theSQL)

pbcDB.close
set pbcDB = Nothing

%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
<link href=&quot;css/style.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;>
</head>
<body>
<br>
<br>
<table width=&quot;200&quot; cellpadding=&quot;4&quot; cellspacing=&quot;4&quot; border=&quot;2&quot;>
<tr>
<td>p_salesman :</td>
<td><%= p_salesman %><br></td>
</tr>
<tr>
<td>p_saleDate: </td>
<td><%= p_saleDate %><br></td
></tr>
<tr>
<td>p_projectName:</td>
<td><%= p_projectName %><br></td>
</tr>
<tr>
<td>p_lotNum:</td>
<td><%= p_lotNum %><br></td>
</tr>
<tr>
<td>p_phase:</td>
<td><%= p_phase %><br></td>
</tr>
<tr>
<td>p_customer:</td>
<td><%= p_customer %><br></td>
</tr>
</table>
</body>
</html>


any help is appreciated. Thanks

dhayden@wecantlose.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top