Click to See Complete Forum and Search --> : Getting a Radio Button Value


Picarolio
07-30-2003, 09:04 AM
I posted here yesterday and got a wealth of information but I'm stuck on one part that didn't work. I have a form that is being used to link to various pages depending upon what is selected in a combo box and radio buttons.

here is a snipet of the code:

<!--Begin
var link_to_report = "";

var region = document.Network_Reports.Combo_Regions.value;
var report = document.Network_Reports.R1.value;

parent.location="Network/reports/" + report + "/" + report + "" + region +".xls";
}
// End -->

The combo box is able to get the value but the radio button always returns undefined/null value. What do I need to do to be able to get the value of the selected R1 radio button.

Thanks for all help and remarks (even smart ass ones)!

Fang
07-30-2003, 09:29 AM
If you have more than one radio button with the same id, you need to find the selected radio button:

for(var i=0; i<R1.length; i++) {
if(R1[i].checked==true) {
alert(R1[i].value);
break;
}
}

Picarolio
07-30-2003, 09:34 AM
What if I just change all of the ids of the radio buttons? then could I use the code that I have?

Fang
07-30-2003, 10:20 AM
Is this what you want to do:

<form method="POST" name="Network_Reports">

<p><b><a href="Network/Default.htm">Network</a></b></p>

<p>Please Select Your Region <select size="1" name="Combo_Regions">
<option value="Atlanta">Atlanta</option>
<option value="Baltimore Metro">Baltimore Metro</option>
<option value="Western">Western</option>
</select></p>

<p><input type="radio" name="R1" value="Plus">Plus</p>
<p><input type="radio" name="R1" value="Classic">Classic</p>
<p><input type="radio" name="R1" value="Commercial">Commercial</p>

<p><input type="button" value="Get Report" name="B1" onClick="return Get_Report(this.form);"></p>

</form>
<script type="text/javascript">
<!--
var link_to_report = "";

function Get_Report(f){
var R1value="";
for(var i=0; i<f.R1.length; i++) {
if(f.R1[i].checked==true) {
R1value=f.R1[i].value;
break;
}
}
link_to_report = "Network/reports/"+R1value+"/"+R1value+"_"+f.Combo_Regions[f.Combo_Regions.selectedIndex].value+".xls";
alert(link_to_report);
}
//-->
</script>

Picarolio
07-30-2003, 10:28 AM
Thanks,

I didn't understand at first that the radio button was an Array. I've went back and fixed it. Thanks a ton!