submit form with OnClick

S

shank

I've got 2 problems.
Problem #1: I have 2 buttons on a form.
If user clicks on ButtonA, the form gets submitted to PageA.
If user clicks on ButtonB, the form gets submitted to PageB.
One forum promotes using the OnClick event to direct to the correct page.
Another forum says OnClick is not wise because a user could have scripts
disabled.
What is the best way?

Problem #2: What is the proper syntax for the below statement?
I'm having problems with the OnClick portion.
Response.write "<input type='submit' name='Submit2' value='I WANT TO MAIL A
CHECK'
onclick='document.frmReview.action='check.asp';document.frmReview.submit()'>
"

thanks!
 
G

Guinness Mann

There are a number of ways you could do this. I used to separate out the
form page and the processor page because it seemed to keep the code more
distinct. Now I tend to post a form back to itself and then do whatever
validation or processing is necessary before Response.Redirecting to the
next page in the workflow. It's easier than having to come back to the form
page after doing the s-side validation in a separate processor script.

As an old real-time embedded software kind of guy, I attack this problem
as a classic state machine. It requires adding "state" and "event"
hidden variables to each displayed page, but I've found it to be pretty
robust.

The traditional "loop forever" construct is replaced by the
"request/response" mechanism.

I've built some fairly complex processing procedures around a construct
like this:

'~~~~~~~~~~~~~~~~~<State Variable Initialization>~~~~~~~~~~~~~~~~~~
'If these are null then it means we got here from outside the
'Test universe. We will count on the "else" cases in our
'Select statements to fill in the default.
myState = request("state")
myEvent = request("event")

'~~~~~~~~~~~~~~~~~~~~~~~Main Code Starts Here~~~~~~~~~~~~~~~~~~~~~~
' This is a state machine that processes the events:
' Done - User is done with test subsystem
' TakeTest - Take the test
' ViewTest - Look at the test (admin/instructor)
' GradeTest - Score the test
' Cancel - Back out of the current state
' Default - Initialization or an unknown event
'
' With respect to the following states:
' DisplayingGrade - Test grade is being displayed
' GradingTest - Processing student responses
' Opening - Are you sure you want to take this test?
' TakingTest - Student is taking the test
' ViewingTest - Admin/instructor is reviewing the test
'
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~ States ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
select case myEvent
case "Cancel"
Call returnToOpenpage(user.UserType)

case "Done"
Call returnToOpenpage(user.UserType)

case "TakeTest"
Select Case myState
Case "Opening"
Call testGiver(testId, user)
Case "DisplayingGrade"
Call returnToOpenpage(user.UserType)
Case Else
Call testAborted()
End Select
....

case else
Select Case myState
Case "Opening"
Call displayOpening(user)
Case Else
if initializeTest(testId) = False then
Response.Redirect("error.asp")
End If
Call displayOpening(user)
End Select

End Select
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top