2013-04-28 125 views
1

我有這個腳本一個問題,我需要的表單驗證底部的程序性,首先檢查與選擇無線電設備是否有針對性的,然後,然後纔要求從特定的無線電下拉時間開始。這似乎是完整的,如果我能得到:表單驗證檢查選項,並選擇檢查不正常

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> 
+0

這是更好地張貼有效的標記,一些標籤缺失,有些是不匹配的。您還正在使用表單驗證腳本,該腳本應在問題文本中和標籤中按名稱提及。 – RobG 2013-04-28 22:32:48

回答

0

在我看來,你真正想要的是ID爲「第一」的是,當檢查單選按鈕的監聽器,啓用或禁用基於按鈕是否被選中或毗鄰選擇元素不。你可以做到這一點:

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

您應該禁用選擇元素時腳本頁面加載,而不是在HTML。

在選擇元素,您應該設置第一個選項,在HTML選擇:

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

這似乎需要在ID前面的空格=「選擇」

0

您的輸入無線電必須有一個「ID」不只是一個名字。它適用於我..

+0

如果你只是發佈你的另一個,你應該刪除這個答案。 – 2014-07-05 02:48:04

0

更改代碼

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

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

也許這可以幫助..