代码如下,如果文本框不填,根据js里的方法会弹出提示,但是点了对话框的确定以后,程序还是进action了。如何不让他进action呢
function getText()
     {
     var m_New = document.getElementById('m_New').value;
                   if(m_New=="")
     {
     alert("请输入新车价格");
                       document.form1.m_New.focus();
                       return false;
     }
    
     return true;
     } <body>
   <s:form action="computeCnav" namespace="/cnav" id="form1" validate="true">
新车价格:<input type="text" name="m_New" style="width:97" />万元<br>
<input type="submit" value="确定" OnClick="getText();" />
    </s:form>
  </body>

解决方案 »

  1.   

    function getText()
      {
      var m_New = document.getElementById('m_New').value;
      if(m_New=="")
      {
      alert("请输入新车价格");
      document.form1.m_New.focus();
      return;
      }   } <body>
      <s:form action="computeCnav" namespace="/cnav" id="form1" validate="true">
    新车价格:<input type="text" name="m_New" style="width:97" />万元<br>
    <input type="submit" value="确定" OnClick="getText();" />
      </s:form>
      </body>
      

  2.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>js校验</title>
    </head>
    <script language="javascript">
    function getText()
      {
      var m_New = document.getElementById('m_New').value;
      if(m_New==""||m_New==null)
      {
      alert("请输入新车价格");
      document.form1.m_New.focus();
      return false;
      }
      
      return true;
      }
    </script>
    <body>
      <s:form action="computeCnav" namespace="/cnav" id="form1" validate="true">
    新车价格:<input type="text" name="m_New" style="width:97" />万元<br>
    <input type="submit" value="确定" OnClick="getText();" />
      </s:form>
      </body>
    </html>
    对着啊
      

  3.   

    <input type="submit" value="确定" OnClick="return getText();" />
      

  4.   

    else return true;
    行不
      

  5.   

    <script type="text/javascript">
    function getdText(){
    var m_New = document.getElementById("m_New").value;
    if(m_New==""){
    alert("请输入新车价格");
    document.form1.m_New.focus();
    return false;
    }
    return true;
    }
    </script>
    </head><body>  <s:form action="computeCnav" namespace="/cnav" name="form1" id="form1" validate="true">
    新车价格:<input type="text" name="m_New" id="m_New" style="width:97px" />万元<br>
    <input type="submit" value="确定" onclick="return getdText()"/>
      </s:form></body>
      

  6.   

    <input type="submit" value="确定" OnClick=" return getText();" />
      

  7.   

    那个form标签里不是有个onsubmit属性吗  在里面这样写 onsubmit="return getText()" 这样就行了
      

  8.   

    试试看在form onsubmit时做验证,而不是用submit button 的onclick事件
    <form ..... onSubmit="return getText();">
    ....
    <input type="submit" value="确定"/>
    </form>