从其他页面中选择默认单选按钮

时间:2011-03-08 19:00:11

标签: radio-button hyperlink

我正在尝试在一个页面上放置一系列链接,单击这些链接时,将在另一个页面上选择一个广播组的默认值。最好的例子是here。通过单击最右侧的蓝色链接之一,它们将在下一页上定义无线电组的默认值。这正是我想要做的。

任何人都可以帮我理解他们是如何做到的吗?

1 个答案:

答案 0 :(得分:0)

这不是“检查”另一端的方框。您单击的链接包含URL中的变量(GET变量)。加载新页面时,可能使用服务器端脚本语言来测试每个单选按钮。

在这种情况下,?default_amt = 5是$ 5贡献的附加内容。然后,在页面上:

 <input type="radio" checked="checked" value="5" name="amount" id="amt_preset_1" onclick="BSD.contribution.clearother();" class="radiobutton">

是单选按钮的值。简单地把像这个PHP代码的东西“检查”它

 <?php if ($_GET['default_amt'] == "5") {echo "checked=\"checked\"; } ?>

上一页的链接可能是:

 <a href="newpage.html?amount=1">Set amount to 1 on new page</a>
 <a href="newpage.html?amount=2">Set amount to 2 on new page</a>
 <a href="newpage.html?amount=3">Set amount to 3 on new page</a>
 <a href="newpage.html?amount=4">Set amount to 4 on new page</a>

'newpage.html'会有以下内容:

 <input type="radio" value="1" name="toPay"  <?php if ($_GET['amount'] == "1") {echo "checked=\"checked\"; } ?>>
 <input type="radio" value="2" name="toPay"  <?php if ($_GET['amount'] == "2") {echo "checked=\"checked\"; } ?>>
 <input type="radio" value="3" name="toPay"  <?php if ($_GET['amount'] == "3") {echo "checked=\"checked\"; } ?>>
 <input type="radio" value="4" name="toPay"  <?php if ($_GET['amount'] == "4") {echo "checked=\"checked\"; } ?>>
相关问题