我有2个单选按钮1.)访问日志和2.)案例历史记录。并提交按钮" GET Report"。
当我点击案例历史记录时,我得到另外2个子单选按钮,说"事件"和"来源",我的问题是在这些子单选按钮之间进行选择并点击提交后,子单选按钮消失了。
即使点击提交,我也需要收音机子单选按钮。
这是我的代码:
<head>
<script type="text/javascript">
function show() { document.getElementById('area').style.display = 'block'; }
function hide() { document.getElementById('area').style.display = 'none'; }
</script>
</head>
<body>
<form name="radios" method="GET">
<INPUT TYPE=RADIO NAME="X" VALUE="visitlog" onclick="hide();"/>Visit Log
<INPUT TYPE=RADIO NAME="X" VALUE="Case" onclick="show();"/>Case History
<div id="area" style="display: none;">
<INPUT TYPE=RADIO NAME="Y" VALUE="incident" />Incident
<INPUT TYPE=RADIO NAME="Y" VALUE="Source" />Sources
</div>
<input type="submit" name="GETREPORT" value="Get Report" />
</form>
</body>
即使在提交按钮后,如何使用所选的电台选项保留我的2个子单选按钮?请帮忙
答案 0 :(得分:1)
您需要READ
在$_GET
中使用PHP
方法发送的表单值<?php
// default values
$area_display = "none";
$checked_visitlog = "";
$checked_case = "";
$checked_incident = "";
$checked_source = "";
// only if $_GET is not empty
if ( !empty($_GET) ) {
// "x" value
switch ( $_GET["X"] ) {
case "visitlog":
$checked_visitlog = "checked";
break;
case "Case":
$area_display = "block";
$checked_case = "checked";
break;
}
//"y" value
switch ( $_GET["Y"] ) {
case "incident":
$checked_incident = "checked";
break;
case "Source":
$checked_source = "checked";
break;
}
}
?>
。
HTML
然后,当您设置<head>
<script type="text/javascript">
function show() {
document.getElementById('area').style.display = 'block';
}
function hide() {
document.getElementById('area').style.display = 'none';
}
</script>
</head>
<body>
<form name="radios" method="GET">
<input <?php echo $checked_visitlog;?> type="radio" name="X" value="visitlog" onclick="hide();" />Visit Log
<input <?php echo $checked_case;?> type="radio" name="X" value="Case" onclick="show();" />Case History
<div id="area" style="display: <?php echo $area_display;?>;">
<input <?php echo $checked_incident;?> type="radio" name="Y" value="incident" />Incident
<input <?php echo $checked_source;?> type="radio" name="Y" value="Source" />Sources
</div>
<input type="submit" name="GETREPORT" value="Get Report" />
</form>
</body>
</head>
写这些值并添加属性时。
{{1}}
答案 1 :(得分:0)
如果单击了提交按钮,则只需检查您的页面,然后 echo style =“display:block”。否则你 echo style =“display:none”。
当然,重新加载页面后,你的javascript就会消失。
<body>
<form name="radios" method="POST">
<INPUT <?php if (isset($_POST["X"]) && $_POST["X"] == "visitlog") echo "checked ";?> TYPE=RADIO NAME="X" VALUE="visitlog" onclick="hide();"/>Visit Log
<INPUT <?php if (isset($_POST["X"]) && $_POST["X"] == "Case") echo "checked ";?>TYPE=RADIO NAME="X" VALUE="Case" onclick="show();"/>Case History
<?php if (isset($_POST["submit"])) echo "<div id=\"area\" style=\"display:block\">"; else echo "<div id=\"area\" style=\"display:none\">"; ?>
<INPUT TYPE=RADIO NAME="Y" VALUE="incident" />Incident
<INPUT TYPE=RADIO NAME="Y" VALUE="Source" />Sources
</div>
<input type="submit" name="submit" value="Get Report" />
</form>
</body>