我有一个表单,它有一个 foreach 循环,在循环内我有一个输入类型单选,所以每次它都有一个新值,如下面的代码:
<?php
$aircrafts = AircraftPermit::getaircraft();
foreach($aircrafts as $aircraft)
{
$pacas = AircraftPermit::getrouteaircraft($aircraft->name ,$pilotid);
if($pacas)
{
?>
<tr>
<td>
<input type="radio" id="ac" value="" disabled="disabled"><?php echo $aircraft->name ;?><br />
</td>
<td align="center">
<input name="submit" title="Give permission to selected aircraft" type="submit" value="Give Permit" disabled="disabled">
</td>
<td align="center">
<font color="green">Granted</font>
</td>
</tr>
<?php
}
else
{
?>
<tr>
<td>
<input type="radio" id="ac" value="<?php echo $aircraft->name ;?>"><?php echo $aircraft->name ;?><br />
</td>
<td align="center">
<input name="id" type="hidden" value="<?php echo $pilotid ;?>">
<input name="submit" title="Give permission to selected aircraft" type="submit" value="Give Permit">
</td>
<td align="center">
<font color="red">Restricted</font>
</td>
</tr>
<?php
}
}
?>
现在最后我有一个脚本来检查单选按钮是否被选中,如下所示:
<script type="text/javascript">
function radio_is_on() {
var elementId = document.getElementById('ac');
if (elementId.checked==false)
{
alert('Please select the aircraft first!');
return false;
}
if (elementId.value)
{
return true;
}
}
</script>
当单选按钮没有被按下时,消息会弹出,但是当它被按下时,它不返回任何值,并且表单发送空值。请告诉我哪里错了。谢谢