日期:2014-05-18  浏览次数:20804 次

document.form.submit()为什么出错?急!!!
我想在一个form里实现两个不同的提交
我的代码如下:
<script   language= "javascript ">

function   search()
{  


    document.form1.action= "aaaa.jsp?string=submit ";//aaaa.jsp为当前页面
    document.form1.submit();
}
function   check(theform)
  {
      if(theform.dwmc.value== " ")
      {
            window.alert( "单位名称不能为空! ");
    theform.dwmc.focus();
    return   false;
      }
      else
          theform.submit();
  }
</script>
<form   name= "form1 "   method= "post "   actio= "aaaaaServlet '>
.......
<inpurt   type= "button "   name= "search "   value= "搜索 "   onclick= "search() ">
...........
<input   type= "submit "   name= "submit "   value= "查询 "   onclick= "check(document.form1) ">
</form>
可是当单击 "搜索 "按钮时,提示脚本错误(script   error),   search()函数里的document.form1.submit();无法执行,然后单击“查询”按钮,form1的action执行的是 "aaaa.jsp?string=submit ",而不是“aaaaaServlet”。
这是为什么?感觉代码没有错误,为什莫出错,


------解决方案--------------------
你没有指定哪一个form,一个document里可能有很多的form.你可以这样document.forms[0].submit(),试试看
------解决方案--------------------
name= "submit " 换成 name= "Submit "