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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error On Page when calling sub from submit btn on form

Status
Not open for further replies.

dommett

Programmer
Apr 30, 2004
33
US
I am trying to call a sub within the current asp file (written with vbscript) but when I hit the submit button of my frontpage form, I see a quick flash of "Error On Page" in the status bar of IE, then the page reloads. This is something new I am trying so please see if you can spot my error(s) and help a newbie out.
Here's the code:

<html>

<head>
</head>
<%
Dim adoCon
Dim rsCoupon
Dim strSQL
Dim txtActionType
Dim lngID

Sub cmdTakeAction()
'for testing purposes - I just want to see the
'redirection work
Response.Redirect "Default.htm"
' Select Case txtActionType
' Case "Add","Edit"
' rsCoupon.Fields("Company Name") = FrontPage_Form1("CompanyName")
' rsCoupon.Fields("Coupon Description") = FrontPage_Form1("CouponDescription")
' rsCoupon.Fields("Hyperlink to JPEG") = FrontPage_Form1("HyperlinkToJPEG")
' rsCoupon.Fields("Start Date") = FrontPage_Form1("StartDate")
' rsCoupon.Fields("End Date") = FrontPage_Form1("EndDate")
' rsCoupon.Update
' Case "Delete"
' strSQL = "DELETE FROM Main WHERE Main.ID=" & lngID
' adoCon.Execute(strSQL)
' End Select
' rsCoupon.Close
' Set rsCoupon = Nothing
' Set adoCon = Nothing
End Sub

txtActionType = Request.QueryString("Action")
lngID = Request.QueryString("ID")

'Open connection

Set adoCon = Server.CreateObject("ADODB.Connection")

adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ="& Server.MapPath("../fpdb/testcoupon.mdb")

Set rsCoupon = Server.CreateObject("ADODB.Recordset")

if txtActionType = "Add" then
strSQL = "SELECT Main.* FROM Main;"
rsCoupon.CursorType = 2
rsCoupon.LockType = 3
else 'txtActionType is Delete or Edit
strSQL = "SELECT Main.* FROM Main WHERE Main.ID=" & lngID
end if

rsCoupon.Open strSQL, adoCon

if txtActionType = "Add" then
rsCoupon.AddNew
rsCoupon("Start Date") = Date()
rsCoupon("Expiration Date") = DateSerial(Year(Date), Month(Date) + 1, Day(Date)) 'add a month to today
rsCoupon("Hyperlink to JPEG") = "ecoupons/"
end if
%>


<body onload="document.FrontPage_Form1.CompanyName.focus()"><form method="POST" name="FrontPage_Form1">
<h3 align="center"><% Response.Write(txtActionType) & " Coupon" %></h3>
<p align="center">Company Name
<input type="text" name="CompanyName" size="60" value = '<%Response.Write(rsCoupon("Company Name"))%>' tabindex="1"></p>
<p align="center">Coupon Description
<input type="text" name="CouponDescription" size="70" value = '<%Response.Write(rsCoupon("Coupon Description"))%>' tabindex="2"></p>
<p align="center">Hyperlink to JPEG
<!--webbot bot="Validation" s-display-name="Hyperlink to JPEG" s-data-type="String" b-allow-letters="TRUE" b-allow-digits="TRUE" s-allow-other-chars="/" --><input type="text" name="HyperlinkToJPEG" size="50" value=<%Response.Write(rsCoupon("Hyperlink to JPEG"))%> tabindex="3"></p>
<p align="center">Start Date
<input type="text" name="StartDate" size="10" value = '<%Response.Write(rsCoupon("Start Date"))%>' tabindex="4"></p>
<p align="center">Expiration Date
<input type="text" name="ExpirationDate" size="10" value = '<%Response.Write(rsCoupon("Expiration Date"))%>' tabindex="5"></p>
<p align="center">
<input type="submit" value="Submit" name="B1" tabindex="6" onclick="cmdTakeAction"></a><input type="reset" value="Reset" name="B2"></p>
</p>
</form>

<p align="center"></body>

</html>

Thank you!
Amy
 
Hello dommett,

This event handling will not be very hopeful to operate.
[tt] onclick="cmdTakeAction"[/tt]
You call a sub located so-to-speak on the server. It won't do.

regards - tsuji
 
Isn't there anyway to call a sub when the user hits the submit button or do I have to break this small piece of code into 6 files (form for add, action to add, form for edit, action to edit, etc)?
 
dommett,

I'm afraid so. Maybe somebody has better idea. Bottom line is that sub won't be visible to the address space on the client, so it's hopeless as such.

- tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top