Calling a VBScript subroutine/function using html onclick, ASP

二次信任 提交于 2019-12-11 00:35:57

问题


<%@ 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.


回答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




回答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>


来源:https://stackoverflow.com/questions/21244893/calling-a-vbscript-subroutine-function-using-html-onclick-asp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!