Click here to Skip to main content
15,896,268 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a View page called: radio_page.cshtml, it contains two radio buttons. First radio button is checked as default when loading the page. I need when clicking on second radio button to refresh the page and keep selection on second radio button, I am trying that as below, but it does not work. After refreshing the page the selection returns to the first radio button. Please advise. Thanks.

//In View
@Html.RadioButtonFor(m=>m.Value, "KW", new { style = "width:70px", @onClick = "onRadioClick(this);", @checked = "checked" }) KW
@Html.RadioButtonFor(m=>m.Value, "HP", new { style = "width:70px", @onClick = "onRadioClick(this);&" })HP

//JavaScript-In Javascript onradio button click textboxes will be hide & show.
<script type="text/javascript">
function onRadioClick(e)
{
var SelectedValue = e.value;
if (SelectedValue == "HP")
{
document.getElementById("DvHP").style.visibility = "Visible";
document.getElementById("DvKW").style.visibility = "hidden";


}
else {
document.getElementById("DvHP").style.visibility = "hidden";
document.getElementById("DvKW").style.visibility = "Visible";

}
}
</script>
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900