单击时是否可以从1个单选按钮传递两(2)个值


Is it possible to pass two (2) values from 1 radio button when clicked?

我这里有大量的单选按钮,它们的值取自数据库。我想加上休假的类型,但我想不通。为了让自己更清楚,一旦单击"病假"单选按钮并按下提交按钮,"病假"积分或病假可用时间(我的单选按钮的值为(value=$sLeave),同时,病假类型(隐藏类型)将传递到下一页。

我在各种休假中都试过这个:

 if($sLeave!=0)
 {
 ?> 
<input type="radio" name="optLeave" value="<?php echo $sLeave; ?>" onclick="disableTextarea()" /><label for="Sick">Sick</label>
    <input type="hidden" name"leaveType" value="Sick" />
<?php
} 
else
{
?>
<input type="radio" name="optLeave" disabled="disabled" /><label  for="Sick">Sick</label>
<?php
}
?>

但所有类型的休假都将传递到下一页,并输出最后一个隐藏值。不是选定的。

这是代码:

<form id="leaveForm" name="lform" method="get" action="leaveFiled.php" />
if($sLeave!=0)
{
?>  
<input type="radio" name="optLeave" value="<?php echo $sLeave; ?>" onclick="disableTextarea()" /><label for="Sick">Sick</label>
<?php
}
else
{
?>
<input type="radio" name="optLeave" disabled="disabled" /><label for="Sick">Sick</label>

<?php
}
?>
<?php
if($vLeave!=0)
{
?>
<input type="radio" name="optLeave" value="<?php echo $vLeave; ?>" onclick="disableTextarea()" /><label for="Vacation">Vacation</label>
<?php
}
else
{
?>
<input type="radio" name="optLeave" disabled="disabled" /><label for="Vacation">Vacation</label>
<?php
}
?>
<?php                   
if($eLeave!=0)
{
?>
<input type="radio" name="optLeave" value="<?php echo $eLeave; ?>" onclick="disableTextarea()" /><label for="Emergency">Emergency</label>
<?php
}
else
{
?>
<input type="radio" name="optLeave" disabled="disabled" /><label for="Emergency">Emergency</label>
<?php
}
?>
<?php                   
if($mLeave!=0 && $sex=='F')
{
?>
<input type="radio" name="optLeave" value="<?php echo $mLeave; ?>" onclick="disableTextarea()" /><label for="Maternity">Maternity</label>
<?php
}
else
{
?>
<input type="radio" name="optLeave" disabled="disabled" /><label for="Maternity">Maternity</label>
<?php
}
?>
<?php                   
if($pLeave!=0 && $sex=='M')
{
?>
<input type="radio" name="optLeave" value="<?php echo $pLeave; ?>" onclick="disableTextarea()" /><label for="Paternity">Paternity</label>
<?php
}
else
{
?>
<input type="radio" name="optLeave" disabled="disabled" /><label for="Paternity">Paternity</label>
<?php
}
?>
<?php                   
if($uLeave!=0)
{
?>
<input type="radio" name="optLeave" value="<?php echo $uLeave; ?>" onclick="disableTextarea()" /><label for="Union">Union</label>
<?php
}
else
{
?>
<input type="radio" name="optLeave" disabled="disabled" /><label for="Union">Union</label>
<?php
}
?>
<?php                   
if($oLeave!=0)
{
?>
<tr>
<td height="40" colspan="3" align="left">
    <strong>
    <input type="radio" name="optLeave" value="<?php echo $oLeave; ?>" onclick="enableTextarea()" />    
    <label for="Other Leave">Other Leave</label>
    &nbsp;&nbsp;
    <label for="Reason of Leave">Reason of Leave:</label>
    <input type="text" name="reasonLeave" size="35" disabled="disabled" />        
    </strong> 
</td>
</tr> 
<?php
}
else
{
?>
<tr>
<td height="40" colspan="3" align="left">
    <strong>
    <input type="radio" name="optLeave" disabled="disabled" />
    <label for="Other Leave">Other Leave</label>
    </strong>
</td>
</tr> 
<?php
}                       
?>

也许javascript的使用可以解决这个问题,但我希望能找到另一个解决方案。

如果您可以在值中使用带唯一分隔符的diffrent前缀,如下划线()或冒号(:),例如,请病假或其他时使用sleave

<input type="radio" name="optLeave" value="<?php echo "sleave_".$sLeave; ?>" onclick="disableTextarea()" /><label for="Sick">Sick</label>
<input type="radio" name="optLeave" value="<?php echo "uleave_".$uLeave; ?>" onclick="disableTextarea()" /><label for="Union">Union</label>

然后在post中,u可以通过分解函数来分离值,您将获得您的值。

//use same separator here
$opt_leave = explode("_", $_REQUEST['optLeave']);
$leave_type = $opt_leave[0];
$leave = $opt_leave[1];
//now you can use $leave_type to check your conditions by switch or if conditional statements
if($leave_type == 'sleave') {
  // action on sick leave
} else if($leave_type == 'uleave') {
 // action on Union leave
}