Link to home
Start Free TrialLog in
Avatar of bobbit31
bobbit31Flag for United States of America

asked on

button onclick and server-side code

I would like to have access to the Request object upon hitting a button on my page. ie)
<input type=button value="click me" name="test" onclick=test()>

when i click the button, i want to call the test function:

<%
sub test()

   test = Request.Form("Facility")

end sub

%>

But it gives me the following error:
Object Expected.  

It doesn't know what the test function is.  How can i make it so that the onclick event calls the server-side code?

thanks in advance
Avatar of pipecrash
pipecrash

Remember that when the event ONClick get's triggered, the clientside script test(), is located on the client's machine( because client side scripts is copyed out to the client, along with the plain HTML code. That is why you use Serverscripts,....to create plain HTML)
Therefore you just can't call the Serverside, SUB() residing on the WEBserver, from the client.

There is something called RemoteScripting though, which other maybe will tell you about:)
Avatar of Mark Franz
Use Javascript!

<head>
      <title>Untitled</title>
      <SCRIPT LANGUAGE="JavaScript">
      function test(){
      food = document.forms[0].Food.value;
      alert (food);
}
</script>
</head>

<body>
<form onSubmit="return test();">
<input type="text" name="Food">...
<input type="submit" name="submit" value="Submit">
</form>
The only way to call server-side code is to pass the form values to the server as a server-side script variable.
Dear bobbit31,
ASP is a server side scripting language.
if you put a button and put an event handling function to it's onclick event, then it would only have to be a client side Javascript code in the same html page only.

YOu have put
Request.form("facililty")

I am writing a test program try this out.
You could submit the form on a button's click method . Here's how u Do this



---------------------------------
        test.asp
---------------------------------

<script language=Javascript>

// This function gets executed when the button's
// onclick event is executed.
// This client side function checks which button has been pressed
// and calls the asp .

function submitme(obj)
{
if (obj.value == "submit")
{
document.forms[0].hidval.value=obj.value;
document.forms[0].method="Post"
document.forms[0].action="test.asp"
document.forms[0].submit();
}
}
</script>
</HEAD>
<BODY>


<%
function test()

   test = Request.Form("Facility")

end function
submitname= Request.Form("hidval")

if submitname = "submit" then
Response.write test()
end if

%>


<form action=test.asp method=post>
Facility
<input type=text name=facility size=10>
<input type=hidden name=hidval>
<br>
<input type=button value=submit name=butt onclick="submitme(this)">

</form>


ASKER CERTIFIED SOLUTION
Avatar of pratdude
pratdude

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bobbit31

ASKER

Answer accepted
Why did you accept pratdude answer over mine, his is just a copy of mine!
sorry...  I didn't even read the solutions.  I rethought what i wanted to do and went in a different direction.  Pratdude proposed an answer, so i just gave him the points.  I'm sorry.
Well concidering the fact that 40% of your questions are unlocked even though answers have been posted, you are not creating a good record here...

Whatever!