问题如题,我在网上查有的说是脚本错误,有的说<form id="form1" name="form1" method="post" onsubmit="return checkForm()" action="*.do?method=**">onsubmit放在form标签中是先提交表单后调用方法,改成<input type="submit" name="Submit" value="添加" onclick="return checkForm()" />是先验证后提交,但是我检查了js(没有错误)也把验证的改到了onclick事件里,依然验证return false后提交数据,现在把代码贴出:
<script language="javascript" type="text/javascript">
function checkForm(){
var code = document.getElementById("berthcode");
var name = document.getElementById("berthname");
var depart = document.getElementById("parentdepart");
if(code.value.length==0){
alert("泊位代码不能为空!");
return false;
}
}
function comback(){
location.href="berthManager.do?method=getAllBerth";
}

</script>
<body>
<div align="right">带<span class="STYLE1">*</span>为必填的</div>
<form id="form1" name="form1" method="post" action="*.do?method=**">
  <table width="575"  border="0" align="center"  cellpadding="3" cellspacing="1" class="table_style">
    <tr>
      <td width="25%"><span class="left-title">泊位代码:</span></td>
      <td width="75%">
       <input name="berthcode" type="text" id="berthcode" />
      </td>
    </tr>
    <tr>
      <td><span class="left-title">泊位名称:</span></td>
      <td>
        <input name="berthname" type="text" id="berthname" />
      </td>
    </tr>
    <tr>
      <td><span class="left-title">所属部门:</span></td>
      <td>
        <select name="parentdepart" id="parentdepart" >
<option value="0">--请选择--</option>
<logic:iterate id="de" name="alldeparts">
   <option value="${de.departmentid }"><bean:write name="de" property="departmentname"/></option>
   </logic:iterate>
        </select>
        </td>
    </tr>
    <tr>
      <td colspan="2" align="center">
        <input type="submit" name="Submit" value="添加" onclick="return checkForm()" />
        &nbsp;&nbsp;&nbsp;
      <input name="ds" type="button" id="reset" value="返回" onclick="comback()"/>      </td>
    </tr>
  </table>
</form>希望各位大侠给予指导,先谢过.....在线等....

解决方案 »

  1.   

    <html:form  action="ticketinfo.do"   onsubmit="return validateform();" >
    ...
    <html:submit  value=" Save "/>
      

  2.   

     <input type="button" name="Submit" value="添加" onclick="return checkForm()" /> 
    改成 <input type="button" onclick="checkForm()" value="添加">然后改下checkForm这个方法function checkForm(){ 
    var form=document.getElementById("form1"); 
    if(form.berthcode.value.length==0){ 
    alert("泊位代码不能为空!"); 
    return false; 

    form.submit();

      

  3.   

    onclick="checkForm();return false;"
    这样写试试
      

  4.   

    代码太乱了 没咋看
    onsubmit="return checkForm()" 这样写就对了 按纽上就不用调用函数了另外 也可以通过BUTTON来调用这个函数 然后通过函数去提交
      

  5.   

    谢谢大家,4楼的那个应该能行,我刚才检查了js代码发现有个分号是中文状态的,修改以后return false就不提交了,麻烦大家了....谢谢
      

  6.   

    我在网上查有的说是脚本错误,有的说 <form id="form1" name="form1" method="post" onsubmit="return checkForm()" action="*.do?method=**">onsubmit放在form标签中是先提交表单后调用方法,改成 <input type="submit" name="Submit" value="添加" onclick="return checkForm()" />是先验证后提交这本身就说错了
    <form id="form1" name="form1" method="post" onsubmit="return checkForm()" action="*.do?method=**">这个是checkForm()为TRUE时才提交
    <input type="submit" name="Submit" value="添加" onclick="return checkForm()" />
    这只是一个点击事件而已
      

  7.   

    if(code.value.length==0){ 
    alert("泊位代码不能为空!"); 
    return false; 

    后面要返回一个return true;