我有一个表格,为了测试,我想要一个按钮来自动填写每个组中的所有字段,对于复选框和收音机,只需从每个组类型交易中随机选择一个。大多数表格都非常大,出于测试目的,一直选择项目变得很痛苦。
表格的一个例子是:
<div class="rows"><b>Education</b><br>
<select name="edu" id="edu" validate="required:true"><option value="">Select One</option>
<option value="Some High School">Some High School</option>
<option value="High School graduate">High School graduate</option>
<option value="Some college">Some college</option>
<option value="College graduate">College graduate</option>
<option value="Master’s degree">Master’s degree</option>
<option value="Doctorate">Doctorate</option>
</select></div>
<div class="rows"><b>Payor status</b><br>
<select name="payor" id="payor" validate="required:true"><option value="">Select One</option>
<option value="Medicare/Medicaid">Medicare/Medicaid</option>
<option value="Insurance">Insurance</option>
<option value="Self Pay">Self Pay</option>
</select></div><br>
<div class="rows"><b>I am a physician.</b><br>
<input type="hidden" name="type33-8" value="YN">
<label><input type="radio" name="33-8" id="33Y" value="Yes" validate="required:true"> Yes</label>
<label><input type="radio" name="33-8" id="33N" value="No"> No</label><br>
<label for="33-8" class="error">Please select an option</label></div><b>This doctor:</b><br>
<input type="hidden" name="type34" value="6PMultiple">
<div class="rows"><label>1. Appears sincere.</label><br>
<input type="hidden" name="type34-247" value="6PMultiple">
<label><input type="radio" name="34-247" id="341" value="1" validate="required:true" > 1 - Very Strongly Disagree</label>
<label><input type="radio" name="34-247" id="342" value="2" > 2 - Strongly Disagree</label>
<label><input type="radio" name="34-247" id="343" value="3" > 3 - Disagree</label>
<label><input type="radio" name="34-247" id="344" value="4" > 4 - Agree</label>
<label><input type="radio" name="34-247" id="345" value="5" > 5 - Strongly Agree</label>
<label><input type="radio" name="34-247" id="346" value="6" > 6 - Very Strongly Agree</label></div>
<div class="rows"><label>2. Is professional.</label><br>
<input type="hidden" name="type34-248" value="6PMultiple">
<label><input type="radio" name="34-248" id="341" value="1" validate="required:true" > 1 - Very Strongly Disagree</label>
<label><input type="radio" name="34-248" id="342" value="2" > 2 - Strongly Disagree</label>
<label><input type="radio" name="34-248" id="343" value="3" > 3 - Disagree</label>
<label><input type="radio" name="34-248" id="344" value="4" > 4 - Agree</label>
<label><input type="radio" name="34-248" id="345" value="5" > 5 - Strongly Agree</label>
<label><input type="radio" name="34-248" id="346" value="6" > 6 - Very Strongly Agree</label></div>
<div class="rows"><label>3. Speaks clearly.</label><br>
<input type="hidden" name="type34-249" value="6PMultiple">
<label><input type="radio" name="34-249" id="341" value="1" validate="required:true" > 1 - Very Strongly Disagree</label>
<label><input type="radio" name="34-249" id="342" value="2" > 2 - Strongly Disagree</label>
<label><input type="radio" name="34-249" id="343" value="3" > 3 - Disagree</label>
<label><input type="radio" name="34-249" id="344" value="4" > 4 - Agree</label>
<label><input type="radio" name="34-249" id="345" value="5" > 5 - Strongly Agree</label>
<label><input type="radio" name="34-249" id="346" value="6" > 6 - Very Strongly Agree</label></div>
我曾想过遍历所有表单元素:
for ( var i=0; i < document.form1.elements.length; i++ ) {
if ( document.form1.elements[i].type == "radio" ) {
//Something
}
}
我的问题是遍历每个元素,这将适用于选择下拉菜单(尽管不确定如何在那里随机选择一个下拉菜单选项),但这不适用于收音机的名称组。
我曾认为,为了选择下拉选项,我可以运行这个:
Math.random() * (max - min) + min
在获得选项计数以使用返回的整数随机选择一个之后,我不知道这是否可行,因为我没有测试它,因为我被困在无线电问题上。