java script
i m using a radioButtonList in asp.net web form, now i want to get selectedvalue of checked radio button,i used following code
var radio=document.getElementsByName("<%=rdoListSearchOrder.ClientID %>") [0].checked;
but i m getting 'undefined'
what's the wrong in my code thnaks
ishika singhPosted Jul 14, 2009, 1:45 AM
ArshadPosted Jul 13, 2009, 8:41 AM
document.getElementsById("rdoListSearchOrder").checked
because the way you are trying to use that does bind the value at the runtime but that time control doesnot exist thats y. i think its not very clear.
you can also use your old code this
document.getElementsByName("<%=rdoListSearchOrder.ClientID %>") [0].checked
after the body tag.
Cause: before loading the asp.net content(or body tag) you are using the the Control in the Head tag, thats y nothing is coming. you can write your javascript function after the body tag that time it will work.
Regards
Arshad.
ishika singhPosted Jul 13, 2009, 7:49 AM
Subramanyam RompicherlaPosted Jul 13, 2009, 5:55 AM
function getSelectedRadio(buttonGroup) {
// returns the array number of the selected radio button or -1 if no button is selected
if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
for (var i=0; i
return i
}
}
} else {
if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
}
// if we get to this point, no radio button is selected
return -1;
} // Ends the "getSelectedRadio" function
function getSelectedRadioValue(buttonGroup) {
// returns the value of the selected radio button or "" if no button is selected
var i = getSelectedRadio(buttonGroup);
if (i == -1) {
return "";
} else {
if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
return buttonGroup[i].value;
} else { // The button group is just the one button, and it is checked
return buttonGroup.value;
}
}
} // Ends the "getSelectedRadioValue" function
Purushottam RathorePosted Jul 13, 2009, 4:47 AM