对于每个问题,我想编译一个if
语句,其中通过检查每个问题,如果.ReplyType
文本输入等于Single
,那么用户只能选择一个复选框按钮选项,否则如果.ReplyType
文本输入等于Multiple
,那么用户可以选择多个复选框按钮选项.
我的问题是如果根据.ReplyType
文本输入选择单个按钮或多个按钮,如何实现这一点?PHP 或 JavaScript 哪个更好?
下面是相关代码:
<form action='results.php' method='post' id='exam'>
<?php
//COMPILE OPTION BUTTONS
function ExpandOptionType($option) {
$options = explode('-', $option);
if(count($options) > 1) {
$start = array_shift($options);
$end = array_shift($options);
do {
$options[] = $start;
}while(++$start <= $end);
}
else{
$options = explode(' or ', $option);
}
foreach($options as $indivOption) {
echo '<div class="ck-button"><label class="fixedLabelCheckbox"><input type="checkbox" name="options[]" id="option-' . $indivOption . '" value="' . $indivOption . '" /><span>' . $indivOption . '</span></label></div>';
}
}
foreach ($arrQuestionId as $key=>$question) {
?>
<div class="queWrap">
//DISPLAY QUESTION NUMBER FOR EACH QUESTION
<p><?php echo htmlspecialchars($arrQuestionNo[$key]);?></p>
//DISPLAY OPTION CHECKBOX BUTTONS FOR EACH QUESTION
<?php echo ExpandOptionType(htmlspecialchars($arrOptionType[$key])); ?>
//DISPLAY REPLY TYPE TEXT INPUT FOR EACH QUESTION
<p>Reply Type: <input type='text' class='replyType' name='replytype' value='<?php echo htmlspecialchars($arrReplyType[$key]); ?>' /></p>
</div>
<?php
}
?>