Hello all! I am having a bit of trouble with radio buttons. I have a form in which populates records from a table and then are displayed on the next page with radio buttons, which allows the user to select an row to edit. Now in my javascript to find out which radio button is selected only works if theres more than one radio button. If only one is populated and the user selects it, it says none is selected.
My code:
<script language="JavaScript">
function radio_button_checker()
{
// set var radio_choice to false
var radio_choice = false;
// Loop from zero to the one minus the number of radio button selections
if (document.output.selected.length)
for (counter = 0; counter < document.output.selected.length; counter++)
{
// If a radio button has been selected it will return true (If not it will return false)
if (document.output.selected[counter].checked)
{
radio_choice = true;
break;
}
}
if (!radio_choice)
{
// If there were no selections made display an alert box
alert("Please Select a Record to Edit.");
return (false);
}
document.location = "EditRecord.jsp?index=" + counter;
}
</script>
Any suggestions?
Thanks in advance!!
My code:
<script language="JavaScript">
function radio_button_checker()
{
// set var radio_choice to false
var radio_choice = false;
// Loop from zero to the one minus the number of radio button selections
if (document.output.selected.length)
for (counter = 0; counter < document.output.selected.length; counter++)
{
// If a radio button has been selected it will return true (If not it will return false)
if (document.output.selected[counter].checked)
{
radio_choice = true;
break;
}
}
if (!radio_choice)
{
// If there were no selections made display an alert box
alert("Please Select a Record to Edit.");
return (false);
}
document.location = "EditRecord.jsp?index=" + counter;
}
</script>
Any suggestions?
Thanks in advance!!