I have two radio buttons in my form. Now what I found out is that in some browsers (firefox and google chrome) if you refresh the form, is a radio button was selected before the refresh, then after the refresh the radio button is still selected. I want to know is there a way by using javascript code to be able to say no radio buttons should be already selected when page reloads or refreshes or does it all depend on browser?
Below is code for radio buttons in javascript:
var btnRadioO = document.getElementsByName("weightChoice");
var isbtnRadioChecked = false;
for(i=0; i < btnRadioO.length; i++){
if(btnRadioO[i].checked){
isbtnRadioChecked = true;
}
}
if(!isbtnRadioChecked) {
errRadioMsgO.innerHTML = "Please Select whether you want to include a Total Weight for your Session or Not";
tblWeightO.style.display = "none";
isDataValid = false;
}else if(btnRadioO[0].checked==true && weightO.value == 0){
errRadioMsgO.innerHTML = "";
errWeightMsgO.innerHTML = "You are including Weight so it Must be More Than 0";
isDataValid = false;
}else if(btnRadioO[1].checked==true){
errRadioMsgO.innerHTML = "";
errWeightMsgO.innerHTML = "";
tblWeightO.style.display = "none";
}else{
errRadioMsgO.innerHTML = "";
errWeightMsgO.innerHTML = "";
}
Html code:
<table>
<tr>
<th>6: Provide a Total Weight for your Session</th>
<td><input type="radio" name="weightChoice" value="yes" onClick="getWeight()"/> Yes</td>
<td><input type="radio" name="weightChoice" value="No" onClick="getWeight()"/> No</td>
</tr>
</table>
It could be browsers caching the page. Try setting
checked=false
on both radio buttons to begin with. If that does not work, have a look at page cache options.