I am currently using this code but it does return the selected radio button value
var mailcopy = document.getElementById('mailCopy').value;
Please tell any other possible way to get currently selected radio button value using Javascript
I am currently using this code but it does return the selected radio button value
var mailcopy = document.getElementById('mailCopy').value;
Please tell any other possible way to get currently selected radio button value using Javascript
var mailcopy = document.getElementById('mailCopy').checked;
if(mailcopy==true)
{
alert("Radio Button Checked");
}
else
{
alert("Radio Button un-Checked");
}
guess you trying to find the selected radio button inside a group of radiobuttons.. are you using any framework? else refer: http://www.breakingpar.com/bkp/home.nsf/0/CA99375CC06FB52687256AFB0013E5E9
Radio buttons come in groups which have the same name and different ids, one of them will have the checked property set to true, so loop over them until you find it.
function getCheckedRadio(radio_group) {
for (var i = 0; i < radio_group.length; i++) {
var button = radio_group[i];
if (button.checked) {
return button;
}
}
return undefined;
}
var checkedButton = getCheckedRadio(document.forms.frmId.elements.groupName);
if (checkedButton) {
alert("The value is " + checkedButton.value);
}