this.form.submit()不起作用

时间:2014-04-04 07:39:02

标签: html form-submit

    <form name="formUnbook" method="post" action='<%=response.encodeURL("dist-sales-order-edit.do")%>'>
                        <input type="hidden" name="formName"  value=<%=formName%>>
                        <input type="hidden" name="docTableItem" value="<%=docTableItem%>"> 
                        <input type="hidden" name="docKeyItem" value="<%=docKeyItem%>"> 
                        <%eventCalendarLinkName  = "UnBook";%>
<a class="smalllink4" href="#" onClick="fnUnbook();"><%=eventCalendarLinkName%></a>
</form>
......................................................................................
<script language="JavaScript">
        function fnUnbook(){
            answer = confirm('<%=bundle.getString("label_areYouSure")%>');
            if(answer)
            {
                this.form.submit();
            }
        }
    </script>

This.form.submit();不提交表格。有什么建议吗?我也尝试过document.form.submit();但没有奏效。问题在哪里?

6 个答案:

答案 0 :(得分:1)

this.form.submit();更改为document.getElementsByName("formUnbook")[0].submit();

答案 1 :(得分:0)

尝试修改代码(将id添加到表单中):

<form name="formUnbook" id="formUnbook" method="post" action='<%=response.encodeURL("dist-sales-order-edit.do")%>'>
<!-- other stuff here -->

<script type="text/javascript">
function fnUnbook() {
  if( confirm('<%=bundle.getString("label_areYouSure")%>') ) {
    return document.getElementById('formUnbook').submit();
  }
}
</script>

答案 2 :(得分:0)

在调用函数时丢失的上下文,请使用以下代码:

    <form name="formUnbook" id="formUnbook" method="post" action='<%=response.encodeURL("dist-sales-order-edit.do")%>'>
...
    <script language="JavaScript">
           function fnUnbook(elmt){
               answer = confirm('<%=bundle.getString("label_areYouSure")%>');
               if(answer)
               {
                   document.formUnbook.submit();
               }
           }
    </script>

答案 3 :(得分:0)

提供表单的ID

<form id="newForm" name="formUnbook" method="post" action='<%=response.encodeURL("dist-sales-order-edit.do")%>'>
....
....
</form>

并使用getElement方法

function fnUnbook(){
            answer = confirm('<%=bundle.getString("label_areYouSure")%>');
            if(answer)
            {
                document.getElementById("newForm").submit();
                return true;
            }
    }

答案 4 :(得分:0)

将表单ID添加到表单

     <form id="form"......

并从 this.form.submit 更改为

     document.getElementById("form").submit();

希望它有效

答案 5 :(得分:0)

使用全局document表单集合:

for (var i=0; i<document.forms.length; i++){
    var currentForm = document.forms[0];
    if (currentForm.name == 'formUnbook'){
        currentForm.submit();
        break;
    }
}