PDA

Click to See Complete Forum and Search --> : Help ..........


Keiko
Mar 27th, 2001, 03:09 AM
Dear all,

How to define a sub or function in ASP environment?

For e.g. file name is test.asp
When I click the "cmdAnswer" button, I want it to call
"Answer" procedure/sub/function
The code below doesn't work. It always prompts me
"Answer is undefined".

Can anybody help me on this?

<%
Sub Answer
Response.Write ("Hello World")
End Sub

Response.Write ("<input type=button value=AnswerMe name=cmdAnswer onClick='Answer'>")
%>

Thanks in advance
Keiko

Ianpbaker
Mar 27th, 2001, 03:58 AM
Hi keiko.

your problem is that you are trying to use ASP as client side script. ASP is purely for server side programming. try using the following Javascript to sort out you problem

<HTML>
<HEAD>
<script language="javascript">
function Answer()
{
alert('Hello World');
}
</script>
</HEAD>
<BODY>

<input type=button value=AnswerMe name=cmdAnswer onClick='Answer();'>
<BR>

</BODY>
</HTML>

THis will call answer when the button is pressed

Keiko
Mar 27th, 2001, 04:26 AM
Thanks for the reply Ianpbaker,

But I'm using ASP to hide some information.

Anyone else can help me?

Ianpbaker
Mar 27th, 2001, 04:55 AM
Keiko. You will never be able to call that sub with the above code as you are trying to call a server side sub from the clients machine as ASP is not dynamic like that. THe server will procees your page and then terminate, with the client knowing nothing about the sub. what exactly are you trying to do?