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!

help with passing form data 1

Status
Not open for further replies.

bikebanditcom

Programmer
Jun 11, 2003
117
US
Ok,

So i have a form that has this button "Add a part" which adds a new line of form fields to the sheet, but it names each one for example partNumber is renamed to PartNumber_0, all the way thru 1, 2, 3, 4, so on.

below is the javascript i'm using to create the new rows dynamically.

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


var elemTbody, elemRow;
var elemCols = new Array(10);
var elempartNumber, elemQty, elemDealer, elemPrice, elemReason, elemExPartNumber, elemShipped, elemRcvd15Day, elemCrdtToBeIssd, elemCustRestockingFee, elemUnreturnableToSupp;

//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[2] = document.createElement(&quot;td&quot;);
elemCols[3] = document.createElement(&quot;td&quot;);
elemCols[4] = document.createElement(&quot;td&quot;);
elemCols[5] = document.createElement(&quot;td&quot;);
elemCols[6] = document.createElement(&quot;td&quot;);
elemCols[7] = document.createElement(&quot;td&quot;);
elemCols[8] = document.createElement(&quot;td&quot;);
elemCols[9] = document.createElement(&quot;td&quot;);
elemCols[10] = document.createElement(&quot;td&quot;);


//create our text inputs and our select dropdown
elemPartNumber = document.createElement(&quot;input&quot;);
elemQty = document.createElement(&quot;input&quot;);
elemDealer = document.createElement(&quot;select&quot;);
elemMercValue = document.createElement(&quot;input&quot;);
elemReason = document.createElement(&quot;select&quot;);
elemExPartNumber = document.createElement(&quot;input&quot;);
elemShipped = document.createElement(&quot;select&quot;);
elemRcvd15Day = document.createElement(&quot;select&quot;);
elemCrdtToBeIssd = document.createElement(&quot;select&quot;);
elemCustRestockingFee = document.createElement(&quot;select&quot;);
elemUnreturnableToSupp = document.createElement(&quot;select&quot;);

var elemOption;
var elemOption2;

//do the text boxes first
elemPartNumber.name = &quot;partNumber_&quot; + recordCount;
elemPartNumber.type = &quot;text&quot;;

elemQty.name = &quot;qty_&quot; + recordCount;
elemQty.type = &quot;text&quot;;
elemQty.size = &quot;4&quot;

elemMercValue.name = &quot;mercValue_&quot; + recordCount;
elemMercValue.type = &quot;text&quot;;
elemMercValue.size = &quot;8&quot;

elemExPartNumber.name = &quot;exPartNumber_&quot; + recordCount;
elemExPartNumber.type = &quot;text&quot;;

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

elemReason.name = &quot;reason_&quot; + recordCount;
elemReason.size = &quot;1&quot;;

elemShipped.name = &quot;shipped_&quot; + recordCount;
elemShipped.size = &quot;1&quot;;

elemRcvd15Day.name = &quot;Rcvd15Day._&quot; + recordCount;
elemRcvd15Day.size = &quot;1&quot;;

elemCrdtToBeIssd.name = &quot;CrdtToBeIssd_&quot; + recordCount;
elemCrdtToBeIssd.size = &quot;1&quot;;

elemCustRestockingFee.name = &quot;CustRestockingFee_&quot; + recordCount;
elemCustRestockingFee.size = &quot;1&quot;;

elemUnreturnableToSupp.name = &quot;UnreturnableToSupp_&quot; + recordCount;
elemUnreturnableToSupp.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;);
elemDealer.add(elemOption);
elemOption = new Option(&quot;HOUSE&quot;,&quot;HOUSE&quot;);
elemDealer.add(elemOption);
elemOption = new Option(&quot;PARTS&quot;,&quot;PARTS&quot;);
elemDealer.add(elemOption);
elemOption = new Option(&quot;TR&quot;,&quot;TR&quot;);
elemDealer.add(elemOption);
elemOption = new Option(&quot;VLE&quot;,&quot;VLE&quot;);
elemDealer.add(elemOption);
elemOption = new Option(&quot;SOUTH&quot;,&quot;SOUTH&quot;);
elemDealer.add(elemOption);


elemOption2 = new Option(&quot;Select One&quot;,&quot;Select One&quot;);
elemReason.add(elemOption2);
elemOption2 = new Option(&quot;Customer Return&quot;,&quot;Customer Return&quot;);
elemReason.add(elemOption2);
elemOption2 = new Option(&quot;Incorrect or Damaged&quot;,&quot;Incorrect or Damaged&quot;);
elemReason.add(elemOption2);
elemOption2 = new Option(&quot;Exchange&quot;,&quot;Exchange&quot;);
elemReason.add(elemOption2);
elemOption2 = new Option(&quot;BB - No Fee&quot;,&quot;BB - No Fee&quot;);
elemReason.add(elemOption2);
elemOption2 = new Option(&quot;BB - Pay Fee&quot;,&quot;BB - Pay Fee&quot;);
elemReason.add(elemOption2);

elemOption3 = new Option(&quot;Yes&quot;,&quot;Yes&quot;);
elemShipped.add(elemOption3);
elemOption3 = new Option(&quot;No&quot;,&quot;No&quot;);
elemShipped.add(elemOption3);

elemOption4 = new Option(&quot;Yes&quot;,&quot;Yes&quot;);
elemRcvd15Day.add(elemOption4);
elemOption4 = new Option(&quot;No&quot;,&quot;No&quot;);
elemRcvd15Day.add(elemOption4);


elemOption5 = new Option(&quot;Yes&quot;,&quot;Yes&quot;);
elemCrdtToBeIssd.add(elemOption5);
elemOption5 = new Option(&quot;No&quot;,&quot;No&quot;);
elemCrdtToBeIssd.add(elemOption5);


elemOption6 = new Option(&quot;Yes&quot;,&quot;Yes&quot;);
elemCustRestockingFee.add(elemOption6);
elemOption6 = new Option(&quot;No&quot;,&quot;No&quot;);
elemCustRestockingFee.add(elemOption6);


elemOption7 = new Option(&quot;No&quot;,&quot;No&quot;);
elemUnreturnableToSupp.add(elemOption7);
elemOption7 = new Option(&quot;Yes&quot;,&quot;Yes&quot;);
elemUnreturnableToSupp.add(elemOption7);


//add the inputs to the appropriate cells
elemCols[0].appendChild(elemPartNumber);
elemCols[1].appendChild(elemQty);
elemCols[2].appendChild(elemDealer);
elemCols[3].appendChild(elemMercValue);
elemCols[4].appendChild(elemReason);
elemCols[5].appendChild(elemShipped);
elemCols[6].appendChild(elemRcvd15Day);
elemCols[7].appendChild(elemCrdtToBeIssd);
elemCols[8].appendChild(elemCustRestockingFee);
elemCols[9].appendChild(elemUnreturnableToSupp);
elemCols[10].appendChild(elemExPartNumber);


//add the cols to the row
elemRow.appendChild(elemCols[0]);
elemRow.appendChild(elemCols[1]);
elemRow.appendChild(elemCols[2]);
elemRow.appendChild(elemCols[3]);
elemRow.appendChild(elemCols[4]);
elemRow.appendChild(elemCols[5]);
elemRow.appendChild(elemCols[6]);
elemRow.appendChild(elemCols[7]);
elemRow.appendChild(elemCols[8]);
elemRow.appendChild(elemCols[9]);
elemRow.appendChild(elemCols[10]);

//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

//-->
</script>


any ideas how to get all those parts and corresponding info and insert it into a database? thankas dan
 
whew - a lot of code - try researching &quot;cloneNode&quot;, it could save you a lode of coding in the future.

When I work with the submission of a dynamic form, I step through the form elements and load them into a 2-dimensional array and then use the array to load the database OR, as in this example, I could do individual updates....

for each item in request.form
answer = left(replace(trim(request.form(item)),&quot;'&quot;,&quot;''&quot;),255)
if answer = &quot;&quot; then answer = &quot;null&quot; else answer = &quot;'&quot; & answer & &quot;'&quot;
select case true
case inStr(1,item,&quot;finalError&quot;,1) > 0 '<
sql = &quot;UPDATE da_Answers set finalError = &quot; & request.form(item)
case inStr(1,item,&quot;error&quot;,1) > 0 '<
sql = &quot;UPDATE da_Answers set error = &quot; & request.form(item)
case inStr(1,item,&quot;comments&quot;,1) > 0 '<
sql = &quot;UPDATE da_Answers set comments = &quot; & answer
case else
sql = &quot;UPDATE da_Answers set &quot; & right(item,2) & &quot; = &quot; & answer
end select
fieldID = left(item,2)
if not isNumeric(fieldID) then fieldID = left(item,1)
if isNumeric(fieldID) then
sql = sql & &quot; WHERE cbr = '&quot; & cbr & &quot;' AND fieldID = &quot; & fieldID
cn.execute(sql)
end if
next


Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook
 
thanks alot! i'll try that, i just finished writing the following code and am going to test it, if it doesnt work then i'll fiddle with yours. thanks again
<%
set adminDB = Server.CreateObject(&quot;ADODB.Connection&quot;)
adminDB.open &quot;admin&quot;

custInfo = &quot;insert into tblCustInfo &quot;
custInfo = custInfo & &quot;(custName, email) &quot;
custInfo = custInfo & &quot; values ('&quot;&custName&&quot;', '&quot;&email&&quot;')&quot;

adminDB.Execute(custInfo)

orderInfo = &quot;insert into tblOrderInfo &quot;
orderInfo = orderInfo & &quot;(orderID, bDate, bAmount, california, complete) &quot;
orderInfo = orderInfo & &quot; values ('&quot;&orderID&&quot;', '&quot;&bDate&&quot;', '&quot;&bAmount&&quot;', '&quot;&california&&quot;', '&quot;&complete&&quot;')&quot;

adminDB.Execute(orderInfo)

for each partNumber in request.form(&quot;partNumber&quot;)
partInfo = &quot;insert into tblPartInfo (partNumber) values (&quot;&partNumber&&quot;')&quot;
adminDB.Execute(partInfo)
next
for each qty in request.form(&quot;qty&quot;)
partInfo = &quot;insert into tblPartInfo (qty) values ('&quot;&qty&&quot;')&quot;
adminDB.Execute(partInfo)
next
for each dealer in request.form(&quot;dealer&quot;)
partInfo = &quot;insert into tblPartInfo (dealer) values ('&quot;&dealer&&quot;')&quot;
adminDB.Execute(partInfo)
next
for each mercValue in request.form(&quot;mercValue&quot;)
partInfo = &quot;insert into tblPartInfo (mercValue) values ('&quot;&mercValue&&quot;')&quot;
adminDB.Execute(partInfo)
next
for each reason in request.form(&quot;reason&quot;)
partInfo = &quot;insert into tblPartInfo (reason) values ('&quot;&reason&&quot;')&quot;
adminDB.Execute(partInfo)
next
for each UnreturnableToSupp in request.form(&quot;shipped&quot;)
partInfo = &quot;insert into tblPartInfo (shipped) values ('&quot;&shipped&&quot;')&quot;
adminDB.Execute(partInfo)
next
for each UnreturnableToSupp in request.form(&quot;UnreturnableToSupp&quot;)
partInfo = &quot;insert into tblPartInfo (UnreturnableToSupp) values ('&quot;&UnreturnableToSupp&&quot;')&quot;
adminDB.Execute(partInfo)
next
for each CrdtToBeIssd in request.form(&quot;CrdtToBeIssd&quot;)
partInfo = &quot;insert into tblPartInfo (CrdtToBeIssd) values ('&quot;&CrdtToBeIssd&&quot;')&quot;
adminDB.Execute(partInfo)
next
for each Rcvd15Day in request.form(&quot;Rcvd15Day&quot;)
partInfo = &quot;insert into tblPartInfo (Rcvd15Day) values ('&quot;&Rcvd15Day&&quot;')&quot;
adminDB.Execute(partInfo)
next
for each custRestockingFee in request.form(&quot;custRestockingFee&quot;)
partInfo = &quot;insert into tblPartInfo (custRestockingFee) values (&quot;&custRestockingFee&&quot;')&quot;
adminDB.Execute(partInfo)
next

returnsInfo = &quot;insert into tblReturns (orderID, empID, RANEmpID, Rfault, Rshipping) &quot;
returnsInfo = returnsInfo & &quot; values ('&quot;&orderID&&quot;', '&quot;&empID&&quot;', '&quot;&RANEmpID&&quot;', '&quot;
returnsInfo = returnsInfo & Rfault&&quot;', '&quot;&Rshipping&&quot;')&quot;

adminDB.Execute(returnsInfo)

returnsInfo = &quot;insert into tblTransInfo (orderID, empID, RANEmpID, Rfault, Rshipping) &quot;
returnsInfo = returnsInfo & &quot; values ('&quot;&orderID&&quot;', '&quot;&empID&&quot;', '&quot;&RANEmpID&&quot;', '&quot;
returnsInfo = returnsInfo & Rfault&&quot;', '&quot;&Rshipping&&quot;')&quot;

adminDB.close

set adminDB = Nothing
%>
 
well shite, it works, but it inserts each field and its values as one set, then the second field as a second set, so all other fields are blank in each record except the one that corresponds to the code. any ideas?
 
The way you're form data and table are mean that you'll need the 2-dimensional array....

dim fieldArr()
redim fieldArr(9,0) 'assuming 10 total fields for each record'

'if you have fields that do not fit the name_## format, you may need to alter this to handle them'

for each item in request.form
underscorePos = inStr(item, &quot;_&quot;)
recordNum = mid(request.form(item), underscorePos + 1)
if recordNum > uBound(fieldArr,2) then
redim preserve(fieldArr(9,cInt(recNum)))
end if
select case left(item,underscorePos - 1)
case &quot;partNumber&quot;
arrPos = 0
case &quot;qty&quot;
arrPos = 1
case &quot;dealer&quot;
arrPos = 2
'complete for all items

end select
fieldArr(arrPos, cInt(recNum)) = request.form(item)
next

'now just write you sql for each record'
for x = 1 to uBound(fieldArr,2)
sql = &quot;INSERT myTable VALUES(&quot;&_
&quot;'&quot; & fieldArr(0,x) & &quot;',&quot; &_
&quot;'&quot; & fieldArr(1,x) & &quot;',&quot; &_
&quot;'&quot; & fieldArr(2,x) & &quot;',&quot; &_
'continue for all records and add a closing &quot;)&quot;
cn.execute (sql)
next

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook
 
thanks alot for the info but i am not sure how and where to add the needed info. where do i put the sql statements?

i assume that the sql statement is one that runs thru the loop right?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top