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

Please advise - calling a sub

Status
Not open for further replies.

AGNEW2PRG

Technical User
Aug 5, 2003
98
AE
Hi,


I was wondering if this was possible.

I have 2 asp pages, page1.asp has 1 forms for adding records to the database, I have a hidden field in the form that passes a value to page2.asp this variable kicks off a sub that adds the record to the database. once the record has been added you can view it in the listing below in the form.

the record listings below have a delete and update hyperlink. I would like the hyperlink to call a sub on page2.asp when clicked.

I have posted the code below to show you what I'm trying to achieve..

Many Thanks


<-------------Code--------------------------------------->

<!--#include virtual="/includes/connection.asp" -->
<html>
<head>
<title>ADD NEW EXCHANGE RATE TO DATABASE</title>
<script language="vbscript">
Function ValidateForm_onsubmit()

If frmexchrate.strcurrency.value = "" Then
MsgBox "Please enter a Currency Value!"
ValidateForm_onsubmit = False

ElseIf IsNumeric(frmexchrate.strcurrency.value) Then
MsgBox "Currency field can only be text!"
ValidateForm_onsubmit = False

ElseIf frmexchrate.strvalue.value = "" Then
MsgBox "Please enter a Exchange Rate!"
ValidateForm_onsubmit = False

ElseIf not IsNumeric (frmexchrate.strvalue.value) Then
MsgBox "Currency field can only be a number!"
ValidateForm_onsubmit = False

End If
End Function
</script>

</head>
<body>
<div align="left">
<table class="table">
<form action="expcmd.asp" method="post" id="frmexchrate" name="ValidateForm">
<tr><td></td>
<td><Input type="hidden" name="addrec" value="addrec">
</td></td>
<tr>

<tr><td>Currency Type:</td>
<td><Input type="text" name="strcurrency" size="10">
</td></td>
<tr>

<tr><td>Value to GBP:</td>
<td><Input type="text" name="strvalue" size="10">
</td></td>
<tr>

<tr>
<td></td><td><input type="submit" name="cmdValidate" value="Add"><space><space>
<input type="button" value="Cancel" onclick=location.href="/exrate"></td>
<br>
<br>
</tr>

<tr>
</form>
</table>

exrate.asp:

<html>
<head>
<title>Exchange Rate List</title></head>
<body bgcolor="white" text="black">
<%

Dim rsExRate
Dim strSQL
Dim lngRecordNo

lngRecordNo = CLng(Request.QueryString("ID"))


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

strSQL = "SELECT tblexchange.* FROM tblexchange;"

rsExRate.Open strSQL, conn


Response.Write ("<table width='400px' border='0'>")
Response.Write ("<tr>")
Response.Write ("<th align='Left'>CURRENCY</th>")
Response.Write ("<th align='Left'>EXCH RATE</th>")
Response.Write ("<th align='Left'>DEL</th>")
Response.Write ("</tr>")

Do While Not rsExRate.EOF

Response.Write ("<tr>")
Response.Write ("<td align='Left'>")
Response.Write ("<a href=""expcmd.asp?ID=" & rsExRate("ID") & """>")
Response.Write (rsExRate("strcurrency"))
Response.Write ("</td>")

Response.Write ("<td align='Left'>&nbsp;&nbsp;&nbsp;")
Response.Write (rsExRate("strvalue"))
Response.Write ("</td>")

Response.Write ("<td align='left'>")
Response.Write ("<a href=""expcmd.asp?ID=" & rsExRate("ID") & """>")
Response.Write ("Delete")
Response.Write ("</td>")
Response.Write ("<tr>")
rsExRate.MoveNext

Loop
Response.Write ("</table>")

rsExRate.Close
Set rsExRate = Nothing
Set adoCon = Nothing
Set conn = Nothing
%>

" New To Programming - Learning Fast :)
 
... the hyperlink to call a sub on page2.asp ..."

To clarify. A hyperlink sends a request to the web server. The request may contain form data, or it may include a querystring. If the URL is for an ASP script, the web server runs the script. The script may look at the data in the request or the querystring and do different things depending on the values.

For example, if there is a form field named action and it has a value of delete, then the script could call the sub which deletes things. Or if there is an item in the query string such as action=delete.

With links, use the querystring to pass the data which controls the action of the script.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top