View Single Post
Old 12-19-2012, 01:18 AM   PM User | #8
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,054 Times in 4,023 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
I can't give you a full course in writing ASP code here and now. You need to go learn *SOME* things on your own.

You might start here:
http://www.w3schools.com/asp/default.asp

I will tell you that if you are trying to save <form> fields to a database with ASP code (or, for that matter, even if you want to save them to a logal file!) you are much better off using *NAMES* that are incremented by a counter and FORGET ABOUT THE IDs!

Form fields do not, in general, need IDs. So don't use them when you don't need them.

And for the field names, I recommend that you use names that VBScript will *recognize* as names.

So... Here, for example, is my rewrite of one of your functions:
Code:
Sub doAddRow()   
   Dim oTbl, oRow, oCell
   Set oTbl=document.getElementById("mytable")
   Set oRow = oTbl.insertRow
   Set oCell = oRow.insertCell
   oCell.innerHTML= "<input name='Lot_Number_" & count & "' />"
   Set oCell = oRow.insertCell   
   oCell.innerHTML= "<input name='Location_" & count & "' />"
   Set oCell = oRow.insertCell   
   oCell.innerHTML= "<input name='Total_In_" & count & "' />"
   Set oCell = oRow.insertCell   
   oCell.innerHTML= "<input name='Test_1star_" & count & "' />"
   Set oCell = oRow.insertCell   
   oCell.innerHTML= "<input name='Test_2star_" & count & "' />"
   Set oCell = oRow.insertCell   
   oCell.innerHTML= "<input name='Test_3star_" & count & "' />"
   Set oCell = oRow.insertCell   
   oCell.innerHTML= "<input name='Total_Out_" & count & "' />"
   Set oCell = oRow.insertCell   
   oCell.innerHTML= "<input name='Lot_Status_" & count & "' />"
   Set oCell = oRow.insertCell   
   oCell.innerHTML= "<input name='Remark_" & count & "' />"
   count = count+1
End Sub
Now, in your ASP code, you can easily pull the data from all those rows, based on the row count.

Example:
Code:
<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "...you will need to supply a connection string here..."

Set RS = Server.CreateObject("ADODB.Recordset")
RS.Open "yourDbTableName", conn, 3, 3

userid = Session("UserId") ' I won't explain this now...read some tutorials first

For count = 1 To 9999
    lotnum = Trim(Request("Lot_Number_" & count))
    If lotnum = "" Then Exit For ' no more data from form

    RS.AddNew ' add a record to the db
    RS("userid") = userid ' say who this record belongs to
    RS("Lot_Number") = lotnum
    RS("Location") = Trim(Request("Location_" & count))
    RS("Total_In") = Trim(Request("Total_In_" & count))
    RS("Test_1star") = Trim(Request("Test_1star_" & count))
    RS("Test_2star") = Trim(Request("Test_2star_" & count))
    RS("Test_3star") = Trim(Request("Test_3star_" & count))
    RS("Total_Out") = Trim(Request("Total_Out_" & count))
    RS("Lot_Status") = Trim(Request("Lot_Status_" & count))
    RS("Remark") = Trim(Request("Remark_" & count))
 
    RS.Update

Next ' go get another row
RS.Close
conn.Close
%>
But this is getting ahead of you. Way ahead of you. First you have to create the database then create the table that will hold this data. And so on and so on.

You have several weeks of learning ahead of you.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is online now   Reply With Quote
Users who have thanked Old Pedant for this post:
bheema (12-19-2012)