<form name=form1>
<input name=haha>
<input name=haha2>
<input type=button value="提交" onclick=gonext()>
</form>
<script language=javascript>
function gonext()
{
      if(document.getElementById("haha").value=="")
      {
       if(document.getElementById("haha2").value=="")
       {
       alert("错误");
       }
       else
       {
       document.getElementById("haha").value=document.getElementById("haha2").value
       }
      }
      else
      {
       if(document.getElementById("haha2").value=="")
       {
       document.getElementById("haha2").value=document.getElementById("haha").value
       }
      }
      form1.submit()
}
</script>

解决方案 »

  1.   

    这样会提示对话框,但是空的text还是保存到页面上了阿
      

  2.   

    <form name=form1 onsubmit="return gonext(this)">
    <input name=haha>
    <input name=haha2>
    <input type=submit value="提交">
    </form><SCRIPT LANGUAGE="JavaScript">
    function gonext(frm)
    {
      var s1 = frm.haha.value;
      var s2 = frm.haha2.value;
      var s = s1 || s2;
      if(s=="") {alert("两个文本框为空了"); return false;}
      frm.haha.value = frm.haha2.value = s;
      return true;
    }
    </SCRIPT>
      

  3.   

    不好意思,忘加句话
    <form name=form1>
    <input name=haha>
    <input name=haha2>
    <input type=button value="提交" onclick=gonext()>
    </form>
    <script language=javascript>
    function gonext()
    {
          if(document.getElementById("haha").value=="")
          {
           if(document.getElementById("haha2").value=="")
           {
           alert("错误");
                                         return;
           }
           else
           {
           document.getElementById("haha").value=document.getElementById("haha2").value
           }
          }
          else
          {
           if(document.getElementById("haha2").value=="")
           {
           document.getElementById("haha2").value=document.getElementById("haha").value
           }
          }
          form1.submit()
    }
    </script>
      

  4.   

    meizz 的方法也是能把空的text保存到页面上
      

  5.   

    还是不行的说,我觉着 加了 return 或是 return false 应该可以的,但空的数据还是会填到数据库里