在经典的ASP / VB脚本中提交表单

时间:2017-07-20 22:11:30

标签: forms vbscript asp-classic submit form-submit

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

但是,设置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>

2 个答案:

答案 0 :(得分:-1)

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

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();
    }
}

答案 1 :(得分:-1)

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