以经典 ASP / VB 脚本提交表单

Submit form in classic ASP / VB Script

有一个经典的ASP,当点击提交按钮时,它会调用Java脚本函数。脚本包含文本框的验证:frmCode,当此验证通过或文本框为空时,我要提交表单。

但是,Set frm = window.document.forms(0) 抛出一个错误 "800a01a8|Object_required:_''" 我也试过 frm = window.document.forms("form1") 但它也没有用。

如有任何建议,我们将不胜感激。提前谢谢你。

<form Method="post" Action="Test.asp" onSubmit="return OKToSubmit()" id="form1" name="form1" target=_blank>
.....
..... more lines..
.....
<input type="text" id="frmCode" name="frmCode"
style="WIDTH: 248px; HEIGHT: 24px" size=1 maxlength="115">
.....
..... more lines..
.....
<input Type="button" Value="Submit" onClick="OKToSubmit()" id="btnSubmit" name="btnSubmitn">
.....
..... more lines..
.....
<SCRIPT ID=clientEventHandlersVBS type="text/Javascript">
function OKToSubmit(){
var availableCode = new Array();
<%
    Dim frm 'reference to form
    Set frm = window.document.forms(0)

    idx = 0
    for idx = 0 to UBound(codeList)-1 
%>
    availableCode[<%=idx %>] = unescape('<%= Escape(codeList(idx)) %>');

    <% next %>

    var strCode = document.getElementById('frmCode').value;
    var validationFlag = 0;
    loopValidation:
    for (var i = 0; i < availableCode.length; i++) {
        if (strCode == availableCode[i]){
            validationFlag = 1;
            break loopValidation;
        }
    }
    if (validationFlag == 0 && !(strCode == "")){
        alert("Code does not exist. Please check again.");
        document.getElementById('frmCode').value = "";
        <%
        OKToSubmit = False
        %>
    } else {
        <%
            OKToSubmit = True 
            frm.Submit 
        %>

    }
}

</SCRIPT>

看看这是否能满足您的需求:

function OKToSubmit(){
var availableCode = new Array();
var frm = window.document.forms[0];
<%
    idx = 0
    for idx = 0 to UBound(codeList)-1 
%>
    availableCode[<%=idx %>] = unescape('<%= Escape(codeList(idx)) %>');

    <% next %>

    var strCode = document.getElementById('frmCode').value;
    var validationFlag = 0;
    loopValidation:
    for (var i = 0; i < availableCode.length; i++) {
        if (strCode == availableCode[i]){
            validationFlag = 1;
            break loopValidation;
        }
    }
    if (validationFlag == 0 && !(strCode == "")){
        alert("Code does not exist. Please check again.");
        document.getElementById('frmCode').value = "";
        return false;
    } else {
        frm.submit();
    }
}

我在 Java 脚本部分将 document.getElementById("form1").submit(); 从服务器端代码移动到客户端代码。然后它现在正在工作。再次感谢您的所有建议。