bobbit31
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
<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
Use Javascript!
<head>
<title>Untitled</title>
<SCRIPT LANGUAGE="JavaScript">
function test(){
food = document.forms[0].Food.val ue;
alert (food);
}
</script>
</head>
<body>
<form onSubmit="return test();">
<input type="text" name="Food">...
<input type="submit" name="submit" value="Submit">
</form>
<head>
<title>Untitled</title>
<SCRIPT LANGUAGE="JavaScript">
function test(){
food = document.forms[0].Food.val
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.v alue=obj.v alue;
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>
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.v
document.forms[0].method="
document.forms[0].action="
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Answer accepted
Why did you accept pratdude answer over mine, his is just a copy of mine!
ASKER
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!
Whatever!
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:)