Can radio buttons be empty after refreshing a page

I have two radio buttons in my form. Now what I found out is that in firefox, 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?

I tried including in the window.onload=function()

btnRadioO[0].checked==false && btnRadioO[1].checked==false

which I thought would do the trick but it didn’t work. Any ideas?

Below is code for radio buttons in javascript:

window.onload=function(){

var btnRadioO = document.getElementsByName("weightChoice");

btnRadioO[0].checked==false && btnRadioO[1].checked==false;
}

Html code:

   <table>
                <tr>
                <th>6: Provide a Total Weight for your Yourself</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>

In firefox when you refresh the form, any input is saved and not cleared. You can do something like this on jquery

$(document).ready(function(){
$(‘input[type=checkbox]’).attr(‘checked’,false);
})

Thank you that worked perfect when I changed input to radio. Thank you for your help :slight_smile:

There is no need for jquery at all for something so basic as unchecking radio buttons and if you look at the “back end” javascript that jquery runs to perform the same task you’ll probably find jquery runs a lot more code.

Yeah, I am sure the javascript code will be much more suitable for this task. But unfortunately I am not really familiar with Javascript OOP. If you could share the code how to do it in jquery, it would be awesome.

Just place the following at the very bottom of the JavaScript attached to the bottom of the web page and it will do the job for you without needing the 40k+ jQeury library.


var inp = document.getElementsByTagName('input');
for (var i = inp.length-1; i>=0; i--) {
if ('radio'===inp[i].type) inp[i].checked = false;
}