VBScript隐藏/取消隐藏文本框

时间:2014-02-12 16:51:00

标签: vbscript asp-classic

所以我在我的asp页面上有以下代码,它们应隐藏/取消隐藏文本框,具体取决于两个条件以及它们是否都满足。

if request.form("Requester_Presenter") = 1 and request.form("Additional_Presenters") = 0 then
    ErrorMessage = ErrorMessage + "<dd>- If you are not a presenter, there must be additional presenters selected so you can provide their contact information in the next step.</dd>"
    document.form.presenters.style.display = "none"
end if

if request.form("Requester_Presenter") = 0 and request.form("Addition_Presenters") = 0 then'do something'
document.form.presenters.style.display = "block"
end if

但是当我运行我的代码时,我收到以下错误:

Microsoft VBScript runtime error '800a01a8' 

Object required: 'document' 

表示我在设置文本框的行上遇到我的错误:none;或显示:block;

我在这里做错了什么?

1 个答案:

答案 0 :(得分:2)

经典ASP(vbScript)是一种服务器端脚本语言,您尝试将服务器端代码与客户端代码混合(document在javascript中可用,并表示DOM中当前加载的页面)

你能做什么,是将这段代码嵌入到脚本html标签中并输出一些javascript:

<script type="text/javascript">
    <%
    if request.form("Requester_Presenter") = 1 and request.form("Additional_Presenters") = 0 then
        ErrorMessage = ErrorMessage + "<dd>- If you are not a presenter, there must be additional presenters selected so you can provide their contact information in the next step.</dd>"
    %>
        document.form.presenters.style.display = "none"
   <%
   end if

   if request.form("Requester_Presenter") = 0 and request.form("Addition_Presenters") = 0 then 'do something'
   %>
       document.form.presenters.style.display = "block"
   <% end if %>
</script>