PDA

View Full Version : passing value to next page


petertran123
06-11-2003, 03:52 PM
Hello all,

I have a code below that shown all the records in my database. I currently have had 20 records total that's show on the page and there are a check box come with it. With 20 records and 20 checkbox will be shown. Now, i want to be able to pass the value that i've selected to the next page. Let say there are 20 checkbox, and i only want to select 5 checkbox and press on submit, the value will be sent 5 records that i've selected to next page instead of showing all 20. I'm sorry that i can't explain well. Please help me with your best. Thanks

<HTML>
<HEAD>

<BODY>

<%
'Open a connection to the database
Dim objConn
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = "DSN=Products"
objConn.Open

'Get the table information for products
Dim objRS
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open "Products", objConn, adOpenForwardOnly, adLockReadOnly, adCmdTable

'Display the FORM and the top of the TABLE
Response.Write "<FORM METHOD=POST ACTION=""UpdateProducts.asp"">"
Response.Write "<TABLE BORDER=1 CELLSPACING=1>"
Dim iLoop
Response.Write "<TR>"
Response.Write "<TH>Update</TH>"
Response.Write "<TH>Name</TH>"
Response.Write "<TH>Cost</TH>"
Response.Write "</TR>"

Dim iCount
iCount = 0

'Display the name and price of each product
Do While Not objRS.EOF
Response.Write "<TR>" & vbCrLf

'Create a checkbox to check for deleting, setting the checkboxes
'Value equal to the current items ProductID
Response.Write "<TD ALIGN=CENTER><INPUT TYPE=CHECKBOX NAME=Delete "
Response.Write "VALUE=" & CInt(objRS("ProductID")) & "></TD>"

'Display the name and cost of the product
Response.Write vbCrLf & "<TD>" & objRS("ProductName") & "</TD>"
Response.Write vbCrLf & "<TD><INPUT SIZE=10 TYPE=TEXT NAME=""" & _
iCount & ".cost"" VALUE=""" & _
FormatCurrency(objRS("UnitPrice"),2) & """ " & _
"STYLE=""text-align:right;"">" & vbCrLf
Response.Write "<INPUT TYPE=HIDDEN NAME=""" & iCount & ".ID"" " & _
"VALUE=""" & objRS("ProductID") & """>" & vbCrLf
Response.Write "</TD></TR>" & vbCrLf & vbCrLf

'Move to the next record...
objRS.MoveNext

'Increment the count variable
iCount = iCount + 1
Loop

'Print the end of the table, the submit button, and the
'the end of the form.
Response.Write "</TABLE>"


'Clean up our ADO objects
objRS.Close
Set objRS = Nothing

objConn.Close
Set objConn = Nothing
%>

<P>
<INPUT TYPE=submit VALUE="Update Product Costs">
<P>
</FORM>
</BODY>
</HTML>

raf
06-11-2003, 04:21 PM
I think i know what you mean. This is how i do it:

Response.Write ("<TD ALIGN=""CENTER""><INPUT TYPE=""CHECKBOX"" NAME=""xxdelxx" & objRS("ProductID") & """")
Response.Write ("VALUE=""8""></TD>")

You see? I add the ProductID to the checkboxes name. If checked, they all get value "8"
Then, when the page is posted, i loop through the formcollection and process all checkboxes (which i select on the "xxdelxx" start of the name. Only checked boxes will be in the formscollection. By stripping of the xxdelxx i then dynamically build my sql statement.
[code]
dim prodcheck
for each prodcheck in request.form
if Left(prodcheck,7) = "xxdelxx" and request.form(prodcheck) = "8" then
blablabla
end if
next

petertran123
06-11-2003, 08:22 PM
Thanks Raf,

i got it working propably. Now i have another issue of leveling submission.

with the submission page: i have three difference level of authentication:

When they click on the checkbox and hit submit button for a FIRST time, then the data will pass to the first level of:

Auth1 = 1
Auth1Stat =1
CheckNum1=1


with second time submission the data will be in
Auth2 = 2
Auth2Stat = 2
CheckNum2 = 2

with Third time Submission the data will go to
Auth3 = 3
Auth3stat =3
CheckNum3 =3

If they are exceed the limit of 3 then they are not allow to submit again, from here whether display a message or redirect to other page. Hope it does make sense to you. The purpose why i want to do that. I want to record a level of user has being submitted to my database. Thanks again

raf
06-11-2003, 08:26 PM
You lost me.

Why do you need three variabels for each submission? I don't quite understand what you try to do. Can you clarify some more?

petertran123
06-11-2003, 10:23 PM
sorry, i should not say 3 submission.

There are three type of authentication:

first authentication contain the value:

Auth1 = 1
Auth1Stat =1
CheckNum1=1


Second Authentication
Auth2 = 2
Auth2Stat = 2
CheckNum2 = 2

Third Authentication
Auth3 = 3
Auth3stat =3
CheckNum3 =3

when the checkbox is selected and submit button was hit as the first time then the data will display the first authentication:

If the same check box is selected and submit button was hit as second time then the data will display as second Authentication

......and third Authentication.

it kinds of looping through each level of authentication. Hope it makes sense to you.

raf
06-11-2003, 10:42 PM
Euhh...

I don't get it. Sorry. Can't you have:
(first authentication)
Auth= 1
AuthStat =1
CheckNum=1
(second authentication)
Auth=2
AuthStat =2
CheckNum=2
...

Anyway, this isn't the actual problem, no? You want to redirect if he authenticated three times?

Something like

Auth3 = 3
Auth3stat =3
CheckNum3 =3

....
if CheckNum3 >=3 then
response.redirect ("the pagename")
else
...
end if

Something like that?

petertran123
06-11-2003, 11:05 PM
do you still member a first question?

There are a checkbox with the data.

Go back to the first question. Let say i have

Page 1 containing 20 records total. I selected 5 checkbox and hit submited..


On page 2 i will have 5 records with the checkbox displayed... Behind this page i just want to know what number of submission does user click by reading from the difference authentication level below.

Okay, on the page 1 i provide 3 type of authentication: which is

first authentication contain the value:
Auth1 = 1
Auth1Stat =1
CheckNum1=1


Second Authentication
Auth2 = 2
Auth2Stat = 2
CheckNum2 = 2

Third Authentication
Auth3 = 3
Auth3stat =3
CheckNum3 =3

when user click on the submit button as the first time then i will know it from first authentication with Auth1, Auth1Stat, CheckNum1

Later if they want to selected the checkbox again and click submit. Now i will know this is a second Authentication with Auth2, auth2Stat, CheckNUm2 value

Once again, they want to select the checkbox again and hit submit button as third time, then i will know value from Third Authentication.

raf
06-12-2003, 08:36 AM
Let me get this straight.
A user ends up on your first page. There are 20 checkboxes there. He checks 5 checkboxes. After submitting he goes to the second page (immedeately or some pages later) where only these 5 checkboxes are displayed. He checkes some and submits. On the third page he gets the remaining checkboxes (?).

But what is actually your question/problem?
Knowing how many times he submitted these checkboxes? (use a sessionvalue. When you build the form, store the value of the sessinvariable in a hidden field. After submitting, when processing the form, increment the value of the sessionvariable)
Knowing which checkboxes he checked? (on the previous page or some pages ago) (previous page --> see my first reply, on previous pages --> store the ID's in a session variable (an array) )
Displaying only the records that were checked on the previous submit?

petertran123
06-12-2003, 03:10 PM
on the first paragraph i got it's working. There are remaining 5 checkboxes on second page.


On second paragraph, you got me...i want to be able to tell there are how many time user submitted these checkboxes. The reason why i did that, i generate a daily report by using crystal report. When user selected 5 checkboxes and 5 reports will be displaying, then user submitted the form. ( there are actually a print button as i called submit) When user decide to select 5 checkboxes and print out 5 reports. Okay from here i want to have some kind of hidden field to record how many time does user select checkbox and hit print button(submit button) .

In addition, i want to give a user up to 3 times of printing (talk about checkboxes and hit submit button up to 3 times). Each time print i want to record this is a first time user prints, or this is a second time user prints, else ...That is why i set 3 level of time show below.

first time select check box and print the value will be recording :
Auth1 = 1
Auth1Stat =1
CheckNum1=1


Second time will record this
Auth2 = 2
Auth2Stat = 2
CheckNum2 = 2

Third time will record this
Auth3 = 3
Auth3stat =3
CheckNum3 =3

raf
06-12-2003, 03:35 PM
I think i understand now what you're trying to do, but what is your problem/question?

I think the routine is:
Page 1: all records. User makes selection
Page 2 : selected records shown. Can be selected here. If submitted --> Page 3 or Page 2 if this is a multipurpose page
Page 2/3 : selected records (reports) are printed.

Last question :
-User can only give 3 printjobs (for 1 or more selected records from page 2) OR each report can only be printed three times?

I assume from your explanation it's 3 printjobs, and that you are just trying to prevent a user from printing more then three times.
The easiest way to do this is using a sessionvariable.
When he submits page 2, you just need some code like

session("printtimes") = session("printtimes") + 1
if session("printtimes") > 3 then
response.redirect("fileadress")
else
code for printing
end if

But it's probably safer to increment the sessionvariable after printing and to check for this variabel before you reload Page 2. Then the check comes on top of page 2 like

if session("printtimes") > 3 then
'response.redirect("fileadress")
response.write("You are not allowed to print reports from this selection more then 3 times")
else
code to display the selection etc
end if


I don't understand why you use 9 variabels for that?

Make sure you set the sesionvariabel back to 0 if you want to permit the user to print reports from another selection.

petertran123
06-12-2003, 04:15 PM
Yes yes yes, that is what exactly i'm trying to do. I want each report only can be printed up to 3 times. With a 9 variables i'm using to tell me what level of time they are printing. I can use a case statement, but not sure how is going to work. Here is my example: Please check

dim myCheckBoxAll

myCheckBoxAll = request("CheckBox")

Select Case myCheckBoxAll

Case "First time"
Auth1 = "1"
Auth1Stat = "1"
CheckNum1 = "1"


Case "Second Time"
Auth2 = "2"
Auth2Stat = "2"
CheckNum2 = "2"


Case "Third Time"
Auth3 = "3"
Auth3Stat = "3"
CheckNum3 = "3"



Case Else
............blah blah

End Select

raf
06-13-2003, 11:11 AM
That select looks right, but i don't know what the values of that "request("CheckBox")" are. Or where it comes from (is it a variabel in the forms collection?)

Don't wanna be annoying but i still don't get why you don't simply use a session variabel or a hidden field...

petertran123
06-13-2003, 03:19 PM
this is a value of page one


Dim iCount
iCount = 0

'Display the name and price of each product
Do While Not objRS.EOF
Response.Write "<TR>" & vbCrLf

'Create a checkbox to check for printing, setting the checkboxes
'Value equal to the current items ProductID
Response.Write "<TD ALIGN=CENTER><INPUT TYPE=CHECKBOX NAME=Checkbox "
Response.Write "VALUE=" & CInt(objRS("ProductID")) & "></TD>"

'Display the name and cost of the product
Response.Write vbCrLf & "<TD>" & objRS("ProductName") & "</TD>"
Response.Write vbCrLf & "<TD><INPUT SIZE=10 TYPE=TEXT NAME=""" & _
iCount & ".cost"" VALUE=""" & _
FormatCurrency(objRS("UnitPrice"),2) & """ " & _
"STYLE=""text-align:right;"">" & vbCrLf
Response.Write "<INPUT TYPE=HIDDEN NAME=""" & iCount & ".ID"" " & _
"VALUE=""" & objRS("ProductID") & """>" & vbCrLf
Response.Write "</TD></TR>" & vbCrLf & vbCrLf

'Move to the next record...
objRS.MoveNext

'Increment the count variable
iCount = iCount + 1
Loop

'Print the end of the table, the submit button, and the
'the end of the form.
Response.Write "</TABLE>"


'Clean up our ADO objects
objRS.Close
Set objRS = Nothing

objConn.Close
Set objConn = Nothing


then the value will be passing to page 2. Which i use case statement


dim myCheckBoxAll

myCheckBoxAll = request("CheckBox")

Select Case myCheckBoxAll

Case "First time"
Auth1 = "1"
Auth1Stat = "1"
CheckNum1 = "1"


Case "Second Time"
Auth2 = "2"
Auth2Stat = "2"
CheckNum2 = "2"


Case "Third Time"
Auth3 = "3"
Auth3Stat = "3"
CheckNum3 = "3"



Case Else
............blah blah

End Select


the problem is i don't know how to retrieve the data from 3 cases above. I want to be able to tell this is my second submission and the value will be looping to case 2. If third submission then the data loop to case 3. Please advise...thanks

raf
06-13-2003, 04:10 PM
i'd think

session("numsubmission") = session("numsubmission") +1
Select Case session("numsubmission")

Case "1"
Auth1 = "1"
Auth1Stat = "1"
CheckNum1 = "1"

Case "2"
Auth2 = "2"
Auth2Stat = "2"
CheckNum2 = "2"

Case "3"
Auth3 = "3"
Auth3Stat = "3"
CheckNum3 = "3"

Case Else
............blah blah

End Select