表单验证器检查选项并选择检查不起作用

时间:2013-04-28 21:59:10

标签: javascript html forms

我遇到了这个脚本的问题,我需要在底部编写表格验证器,首先检查选择的无线电是否是目标,然后再从该特定无线电下拉列表请求时间。如果我能得到:

,它似乎是完整的
if (document.getElementById('first').checked) {
    frmvalidator.addValidation("selects", "dontselect=000", "select a time");
}

语句在javascript中工作,但因为它只查找它的真实时间,但我似乎缺少一些东西。请协助

<form method="POST" name="contactform" id="contactform" action="contact-form-handler.php">
  <div>
    <div style="float:left; width:420px;";>
      <input type="radio" name="radios" id="first" value="SELECT" /> Attending a GROUP Intro      to Meditation ($15) on: <br/>
      <select name="selects"id="selects">
        <option value="000">Select a Date</option>
        <option value="2">April 23rd, TUES at 7:00PM - Group Intro to Meditation</option>
        <option value="3">April 27th, SAT at 11:00AM - Group Intro to Meditation</option>
        <option value="4">May 1st, WED at 7:00PM - Group Intro to Meditation</option>
        <option value="5">May 7th, TUES at 7:00PM - Group Intro to Meditation</option>
  </select>
      <br>
      <input type="radio" name="radios" value="radio1" /> Scheduling a PRIVATE Intro to    Meditation ($200) <br/>
      <input type="radio" name="radios" value="radio2" /> Scheduling an Individual Consultation ($300 / $475) <br/>
      <input type="radio" name="radios" value="radio3" /> GIFT a Mentoring Session - 2 hr ($350) <br>
      <input type="radio" name="radios" value="radio4" /> Corporate Programs <br/>
      <input type="radio" name="radios" value="radio5" /> Pro Bono Programs <br/>
      <input type="radio" name="radios" value="radio6" /> General Inquiry <br/>
      <input type="radio" name="radios" value="radio7" /> Receiving Information on Future      Intro Dates<br/>
    </div>
    <div style="float:left";>
      <label for='name'>Your Name:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
      <input type="text" name="name"> <br>
      <label for='email'>Email Address:&nbsp;</label>
      <input type="text" name="email"> <br>
      <label for='confirm_email'>Confirm Email:</label>
      <input type="text" name="confirm_email"> <br>
      <label for='email'>Contact #:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
      <input type="text" name="contact"> <br>
      <label for='message'>Message:</label> <br>
      <textarea rows="8" cols="35" name="message";></textarea>
      <input type="submit" value="Submit"><br>
    </form>
  </div>
</div>
</td>
<tr>
  <td>
    <script language="JavaScript">
      // Code for validating the form
      // Visit http://www.javascript-coder.com/html-form/javascript-form-validation.phtml

      // for details
      var frmvalidator  = new Validator("contactform");
      frmvalidator.addValidation("name","req","Please provide your name"); 
      frmvalidator.addValidation("email","req","Please provide your email"); 
      frmvalidator.addValidation("email","email","Please enter a valid email address"); 

      //frmvalidator.addValidation("selects","dontselect=000","select a time");
      var chktestValidator = new Validator("contactform"); 

      //chktestValidator.addValidation("radios","selectradio","Please select an option"); 
      chktestValidator.addValidation("radios","selone", "Please select a plan");

      if(document.getElementById('first').checked) {
        frmvalidator.addValidation("selects","dontselect=000","select a time");
      }
  </script>

4 个答案:

答案 0 :(得分:0)

在我看来,你真正想要的是一个id为“first”的单选按钮上的监听器,当选中时,根据是否选中该按钮启用或禁用相邻的select元素。你可以通过以下方式做到:

<input type="radio" ... onclick="this.form.selects.disabled = !this.checked;">

当页面按脚本加载时,应禁用select元素,而不是HTML。

在select元素中,您应该在HTML中将第一个选项设置为选中:

  <option value="000" selected>Select a Date</option>

答案 1 :(得分:0)

似乎在id =“choose”

前面需要一个空格

答案 2 :(得分:0)

您的输入广播必须有一个“ID”而不仅仅是一个名称..它对我有用..

答案 3 :(得分:0)

更改您的代码

<input type="radio" name="radios" value="radio1" />

<input type="radio" name="radios" value="radio1" id="radios" />

也许这可以帮助..