此代码在Windows XP,7等中运行良好...但是在Windows Mobile 5.0中将会使用它。任何帮助将不胜感激!!
//javascript validation
<script>
function validateRadios()
{
var notes = document.getElementsByName("notes[]");
var validateForm = document.getElementsByName("validateForm");
var hours = document.getElementById("hours").value;
for (var i=0;i<validateForm.length;i++)
{
if(validateForm[i].value == 0)
{
alert("You must check a value for each option");
return false;
}
if(validateForm[i].value == 2 && notes[i].value=="")
{
alert("If you selected NO you must enter notes to explain.");
return false;
}
}
if (confirm("Are you sure that you want to submit form?"))
{
return true;
}else
{
return false;
}
</script>
这是php代码。它循环通过数据库将问题吐出到表单中。有一个名为validateFnorm的隐藏字段,JS循环验证单选按钮。
<form name='myForm' action="submits.php" method="POST" onsubmit="return validateRadios();">
</table>
</div>
<table id="inspectionData">
<tbody>
<?PHP
$sql="SELECT * FROM inspection_questions WHERE inspection_form_id = '" .$form. "' AND active = 1"; $query = mysql_query($sql,$con);
while($row=mysql_fetch_array($query))
?>
<tr>
<td colspan="2" style="border-bottom-style:none;"><?echo $row['question_text'];?></td>
<td><label for='yes_<?echo $row['question_id'];?>'>YES</label><input id='yes_<?echo $row['question_id'];?>' name='results_<?echo $row['question_id'];?>'type='radio' class="choice" onclick="showHideNotes(<? echo $row['question_id']; ?>,this.value)" value='1'/>
<label for='no_<?echo $row['question_id'];?>'>NO</label><input id='no_<?echo $row['question_id'];?>' name='results_<?echo $row['question_id'];?>'type='radio' class="choice" onclick="showHideNotes(<? echo $row['question_id']; ?>,this.value)" value='2'/>
<label for='na_<?echo $row['question_id'];?>'>N/A</label><input id='na_<?echo $row['question_id'];?>' name='results_<?echo $row['question_id'];?>' type='radio' class="choice" onclick="showHideNotes(<? echo $row['question_id']; ?>,this.value)" value='3'/>
<textarea id='maintenanceNotes_<?echo $row['question_id'];?>' name='notes[]' cols='10' style="display:none" rows='4' cols='100'></textarea></td></tr>
<input type='hidden' id='validateForm_<?echo $row['question_id'];?>' name='validateForm' value="0">
<input type='hidden' name='numberOfColumns' value="<?echo $i;?>">
<input type='hidden' name='myid[]' value="<?echo $row['question_id'];?>">
<?
}
?>
</tbody>
</table>
</form>