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"];
}
Do this server-side. Set the attribute
checked="checked"
in the radio button that is selected.I presume that your code is something like this: