I am trying to run the following vbscript code (see SCRIPT CODE below)
using an onclick event on a button(see BUTTON CODE below). I am
getting the "error: object expected" at the button code line.

Is there a fundamental problem with my script , i.e. trying to run a
server side script using a button or is there merely a coding error???

I was hoping to run this code automatically when the page loads
pulling in the txt_ClientCode value from a cookie but when i used the
line txt_ClientCode = request.cookie("ClientCode") and ran the code as
client side script i got an error on the word request. Can anyone
please give me a few explanations as to what is happening and any
helpful hints.


BUTTON CODE
<input name="testname" type=button onclick="TestMsg()"
style="width:105px;">

SCRIPT CODE
<SCRIPT LANGUAGE=vbscript runat=server>

Function TestMsg()

Dim oRS, strSQL, txt_ClientCode

txt_ClientCode = "G10"

If len(txt_ClientCode)>0 Then

strSQL = "Select ClientCode, PDFName From tbl_PaymentProtectionPDF
Where ClientCode='" & txt_ClientCode & "'"

Set oRS = Server.CreateObject("ADODB.RecordSet")

oRS.Open strSQL,Application("ConnectionString"),adOpenKeyset,adLockOptimistic

If Not (oRS.EOF And oRS.BOF) Then

msgbox(oRS("ClientCode"))

oRS.Delete
oRS.Update

End IF
oRS.Close
Set oRS = Nothing
Response.End
End If
end function
</SCRIPT>

Thanks

Re: vbscript error accessing database client or server ?? by Ray

Ray
Wed Jan 05 08:23:56 CST 2005

Function TestMsg() exists on the server. The client (browser) is
totally unaware of any such function. Remember, ASP is server-based.
It processes code and sends an HTML response back to a client after
doing so. The client will never be aware of anything in <% %> or
<script runat=server></script> tags.

If you want something to happen on the server when the user clicks a
button, use a submit button in a form, or some other means of
triggering the browser to send another request to the server so that
the server knows to process the code.

Also, ASP questions are best handled in
microsoft.public.inetserver.asp.general|db|components


--

Ray at work
Microsoft ASP/ASP.NET MVP


"Colin Graham" <csgraham74@hotmail.com> wrote in message
news:ee261922.0501050336.a6697f3@posting.google.com...
> I am trying to run the following vbscript code (see SCRIPT CODE
below)
> using an onclick event on a button(see BUTTON CODE below). I am
> getting the "error: object expected" at the button code line.
>
> Is there a fundamental problem with my script , i.e. trying to run
a
> server side script using a button or is there merely a coding
error???
>
> I was hoping to run this code automatically when the page loads
> pulling in the txt_ClientCode value from a cookie but when i used
the
> line txt_ClientCode = request.cookie("ClientCode") and ran the code
as
> client side script i got an error on the word request. Can anyone
> please give me a few explanations as to what is happening and any
> helpful hints.
>
>
> BUTTON CODE
> <input name="testname" type=button onclick="TestMsg()"
> style="width:105px;">
>
> SCRIPT CODE
> <SCRIPT LANGUAGE=vbscript runat=server>
>
> Function TestMsg()
>
> Dim oRS, strSQL, txt_ClientCode
>
> txt_ClientCode = "G10"
>
> If len(txt_ClientCode)>0 Then
>
> strSQL = "Select ClientCode, PDFName From tbl_PaymentProtectionPDF
> Where ClientCode='" & txt_ClientCode & "'"
>
> Set oRS = Server.CreateObject("ADODB.RecordSet")
>
> oRS.Open
strSQL,Application("ConnectionString"),adOpenKeyset,adLockOptimistic
>
> If Not (oRS.EOF And oRS.BOF) Then
>
> msgbox(oRS("ClientCode"))
>
> oRS.Delete
> oRS.Update
>
> End IF
> oRS.Close
> Set oRS = Nothing
> Response.End
> End If
> end function
> </SCRIPT>
>
> Thanks