自动提交一个单选按钮,但保持选中状态 [英] Auto-submit a radio button but keep it selected
问题描述
我使用单选按钮对分页结果进行排序。但是,无论何时单击并自动提交按钮,它都会被取消选中。我想保持选中的按钮,以便用户知道他们选择了哪一个。
> function autoSubmit(){
var formObject = document.forms ['theForm'];
formObject.submit();
< input type =radioname =sortvalue =timeonChange =autoSubmit(); />
< input type =radioname =sortvalue =yearonChange =autoSubmit(); />
< input type =radioname =sortvalue =nameonChange =autoSubmit(); />
if(isset($ _ GET [sort])){
$ sort = $ _GET [sort];
我认为你的代码是像这样:
<?php
$ sort =;
if(isset($ _ GET [sort]))
{$ sort = $ _GET [sort]; }
?>
< html>
< head>
< script>
函数autoSubmit()
{
var formObject = document.forms ['theForm'];
formObject.submit();
}
< / script>
< / head>
< body>
< form name ='theForm'id ='theForm'>
< input type =radioname =sort<?php if($ sort =='upload_time'){?> checked ='checked'<?php}?> value = upload_timeonChange =autoSubmit(); />最近上传的
< input type =radioname =sort<?php if($ sort =='article'){?> checked ='checked'<?php} ?> value =articleonChange =autoSubmit(); />按字母顺序
< input type =radioname =sort<?php if($ sort =='year'){?> checked ='checked'<?php}?> value =yearonChange =autoSubmit(); />最近的
< / form>
< / body>
< / html>
I am using radio buttons to sort through paginated results. However, whenever the button is clicked and auto-submitted, it becomes unselected. I want to keep the button selected so that the user knows which one they selected. How can I do that?
Here is what I have:
function autoSubmit() {
var formObject = document.forms['theForm'];
formObject.submit();
}
<input type="radio" name="sort" value="time" onChange="autoSubmit();" />
<input type="radio" name="sort" value="year" onChange="autoSubmit();" />
<input type="radio" name="sort" value="name" onChange="autoSubmit();" />
if(isset($_GET["sort"])) {
$sort = $_GET["sort"];
}
I presume that your code is something like this:
<?php
$sort = "";
if(isset($_GET["sort"]))
{ $sort = $_GET["sort"]; }
?>
<html>
<head>
<script>
function autoSubmit()
{
var formObject = document.forms['theForm'];
formObject.submit();
}
</script>
</head>
<body>
<form name='theForm' id='theForm'>
<input type="radio" name="sort" <?php if ($sort == 'upload_time') { ?>checked='checked' <?php } ?>value="upload_time" onChange="autoSubmit();" />Recently Uploaded
<input type="radio" name="sort" <?php if ($sort == 'article') { ?>checked='checked' <?php } ?> value="article" onChange="autoSubmit();" /> Alphabetically
<input type="radio" name="sort" <?php if ($sort == 'year') { ?>checked='checked' <?php } ?> value="year" onChange="autoSubmit();" /> Most Recent
</form>
</body>
</html>
这篇关于自动提交一个单选按钮,但保持选中状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!