我正在创建一个表单,根据选择的单选按钮生成一个下拉列表。
日记帐名称存储在类型为1或2的表中。选择单选按钮日记时,日记帐类型的过滤器将为1,而另一个将为2.我使用以下代码生成表单
<?php
$ctype = 1 // $ctype created for filtering purpose
?>
<p> Article For:
Journal <input type="radio" name="article_for" value="Journal" id="article_journal" />
Conference <input type="radio" name="article_for" value="Conference" id="article_conference" />
</p>
<?php
// $ctype will depend upon selection from radio button. If selection is "Journal"
// value of $ctype to set 1 otherwise to set 2.
$selectrecord = "SELECT `content_id`, `content_type`, `content_name` FROM `content` where `content_type` = $ctype";
$result = mysqli_query($connection,$selectrecord) or die(mysqli_error($connection));
?>
<p> Journal Name:
<select name='content_id'>
<?php
while ($row = $result->fetch_assoc()) {
unset($id, $name);
$id = $row['content_id'];
$name = $row['content_name'];
echo '<option value="'.$id.'">' . $name . '</option>';
}
?>
</select>
</p>
我可以使用类似
的代码检查所选的单选按钮if(document.getElementById('article_journal').checked) {
但是在这个if子句中,我不能为变量$ ctype赋值 - 它用于过滤下拉列表的名称。
请帮助我找出我做错了什么。
最好的问候。
答案 0 :(得分:0)
最后,我决定创建多个页面,其中相关字段在物理上位于相当远的形式。 POST变量解决了这个问题。在它们彼此相邻的地方,我使用jQuery来过滤选项。