Calling a VBScript subroutine/function using html onclick, ASP
19,427
Solution 1
Classic ASP runs on the server. Click events happen on the client. There is no persistent connection between the two. Web programming is not the same as desktop app programming.
At a basic level, your code needs to follow this pattern:
BROWSER - click -> request to server -> server processes request -> serves new page -> BROWSER
Solution 2
An onclick event won't work server side for the reasons Diodeus explains. .You need to use the Request object to collect form data. This should do what I think you're trying to achieve.
<%@language="VBScript"%>
<!DOCTYPE html>
<html>
<body>
<form method="post">
<input type = "submit" name="mybutton" value = "Submit"/>
</form>
<%
If Request.Form("mybutton") <> "" then
Response.write("TEST")
End If
%>
</body>
</html>
Author by
user1744228
Updated on June 05, 2022Comments
-
user1744228 almost 2 years
<%@ language = "VBScript"%> <!DOCTYPE html> <html> <body> <form method="post" action = ""> <input type = "submit" onclick = "check()" value = "Submit"/> </form> <% sub check() Response.write("TEST") end sub %> </body> </html>
When I click on the submit button, this doesn't print "TEST" for some reason.
-
John over 10 yearsStrictly speaking it's Classic ASP which runs on the server. You can use VBScript or Javascript as your scripting language in Classic ASP. You can also run VBScript client side in the same way as Javascript, but only IE supports it
-
user1744228 over 10 yearsThanks a lot! Makes sense!
-
Diodeus - James MacFarlane over 10 yearsYes, this is true, but anyone doing this is crazy.
-
John over 10 yearsYou find client side VBS on intranets more often that you might imagine :(
-
Shadow The Kid Wizard over 10 years@Diodeus Sorry but "VBScript runs on the server" is not accurate and might be misleading. "Classic ASP runs on the server" is more correct, I considered editing but it better be done by you.