0

嗨,我有此代码,您能否指导我在验证过程后如何提交此表格。我的表单操作是 send_survey.php。

这里发生的事情是在我点击提交后它显示 javascript 消息,一切都很好,但它不发送表单。

谢谢你。

<!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>Untitled Document</title>

<SCRIPT LANGUAGE="JavaScript">
    <!--

        function validateForm() {

            var ret = new Boolean();

            ret = true;

            var errMessage = "";

            var a1 = document.forms["form1"]["a1"].selectedIndex;
            var a2 = document.forms["form1"]["a2"].selectedIndex;
            var a3 = document.forms["form1"]["a3"].selectedIndex;
            var a4 = document.forms["form1"]["a4"].selectedIndex;

            if (a1 == 0 || a2 == 0 || a3 == 0 || a4 == 0) 
            {
                errMessage = "Please make sure you answer all the survey";
                ret = false;
            }
            else
            {
                if(a2 == a1)
                {
                    errMessage = ": a2";
                    document.forms["form1"]["a2"].selectedIndex = 0;
                    ret = false;
                }

                if(a3 == a2 || a3 == a1)
                {
                    errMessage = errMessage + ": a3";
                    document.forms["form1"]["a3"].selectedIndex = 0;    
                    ret = false;
                }

                if(a4 == a3 || a4 == a2 || a4 == a1)
                {
                    errMessage = errMessage + ": a4";
                    document.forms["form1"]["a4"].selectedIndex = 0; 
                    ret = false;
                }

                if(errMessage.length > 0)
                    errMessage = "ERROR! duplicate entry! Choose another value for " + errMessage;
            }

            var sOut = "a1: " + a1 + "\n" + "a2: " + a2 + "\n" + "a3: " + a3 + "\n" + "a4: " + a4

            if (errMessage.length > 0) {
                sOut = sOut + "\n" + errMessage;
            }

            sOut = sOut + "\nret: " + ret;

            alert(sOut);

            return ret;

        }   

    // -->
    </SCRIPT>

</head>

<body>
<form id="form1" name="form1" method="post" action="send_survey.php">
  <div id="content">
<article class="post clearfix">
  <header>
    <h1 class="post-title"><a href="#">WHEN I INTRODUCE IDEAS TO OTHERS I WANT TO BE:</a></h1>
    <p class="post-meta">
      <time class="post-date" datetime="2011-05-08" pubdate></time>
    </p>
  </header>
  <p style="text-align:justify">
    <select name="a1" >
      <option value="0" selected="selected" >-</option>
      <option value="1" >1</option>
      <option value="2" >2</option>
      <option value="3" >3</option>
      <option value="4" >4 </option>
    </select>
    sincere, dedicated and ethical person.<br />
    <br />
    <select name="a2"  >
      <option value="0" selected="selected" >-</option>
      <option value="1" >1</option>
      <option value="2" >2</option>
      <option value="3" >3 </option>
      <option value="4" >4</option>
    </select>
    bold, masterful and assertive individual. <br />
    <br />
    <select name="a3"  >
      <option value="0" selected="selected" >-</option>
      <option value="1" >1</option>
      <option value="2" >2</option>
      <option value="3" >3 </option>
      <option value="4" >4</option>
    </select>
    compress, practical and cautios person. <br />
    <br />
    <select name="a4"  >
      <option value="0" selected="selected" >-</option>
      <option value="1" >1</option>
      <option value="2" >2</option>
      <option value="3" >3 </option>
      <option value="4" >4</option>
    </select>
    friendly, jovial and enthusiastic person. </p>
  <footer id="footer">
    <p><span class="buttons">
      <input type="button" onclick="validateForm()" value="Submit" />
    </span></p>
  </footer>
  <div class="video"></div>
  <!-- /.video -->
  <div class="video"></div>
  <!-- /.video -->
</article>
<!-- /.post -->
  </div>
</form>
</body>
</html>
4

1 回答 1

0

将您的事件侦听器添加到表单中:

<form id="form1" name="form1" method="post" action="send_survey.php" onsubmit="return validateForm()">

并使您的按钮类型提交:

<input type="submit" value="Submit" />
于 2013-09-11T04:04:59.273 回答