Click to See Complete Forum and Search --> : ASP Form Array


jfergy
01-10-2006, 09:14 PM
Hello-

I have a form where I have mutiple lines of the same thing. Users will input a type of equipment the ID# and other minute data. Instead of creating a table and column for every line, I would like to create a new row for each line the user inputs. However, i am not sure how i can force the array to know which line goes with what data? You can see an example here:
http://www.ecinsurance.com/test/equipment.htm

any help would be appreciated. I have the following code for simple array inputs. Changes and suggestions to make what i need work would be helpful

if Request.Form <> "" then
CNumber = CNumber
office_name= Request.form("office_name")
Office_ID = Request.form("Office_ID")
Office_purchase = Request.form("Office_purchase")
Office_date = Request.form("Office_date")
Office_cost = Request.form("Office_cost")
Office_condition = Request.form("Office_condition")

MyList = Request.Form("ListID")
myArray = split(MyList,",")
For i = 0 to uBound(myArray)
strSQL = strSQL & "INSERT INTO MyTable (Cnumber, Office_Name, Office_ID, Office_Purchase, Office_Date, Office_Cost, Office_Condition) VALUES (" & CNumber & "," & myArray(i) & ");"
NEXT
GetFromDatabase strSQL
Response.Redirect"newpage.asp"
end if

Ubik
01-11-2006, 01:49 PM
You should name your input fields in such a way that each input field for each piece of equipment has an id number, so that the data can be separated out:

To code your input form use something like:

<%for intOfficeLoopCounter = 1 to 10 %>
<input name="desc<%=intOfficeLoopCounter %>" />
<input name="serial<%=intOfficeLoopCounter %>" />
<select name="purchase<%=intOfficeLoopCounter %>"><option></option></select>
<input name="cost<%=intOfficeLoopCounter %>" />
<select name="newused<%=intOfficeLoopCounter %>"><option></option></select>
<%next%>


Now, each formfiled will come through with an id number that you can loop through and place into the db.

Bullschmidt
01-15-2006, 10:54 PM
Interesting, related link:

Parsing with join and split - 5/9/1999
http://www.4guysfromrolla.com/webtech/050999-1.shtml