View Full Version : Value of a Radio List

07-25-2002, 01:59 PM

I'm having problems with Radio buttons,

I'm returning the value from the database but I can't work out how to check the correct radio button using that value.

Can anyone help me?

Thanks in Advance

Nick Gibbons

Mrs G
07-25-2002, 07:32 PM
Play around with this script to see if it helps with what you are after

The script will identify which radio button is chosen

function resetAll(){ //checks to see if any radio buttons are selected
formfield=document.f1.rad // formname and input names to be checked
if (formfield[i].checked==true){ // if selected
formfield[i].checked=false // deselects
itext.innerText="Which one will you choose?" // the following 3 lines resets text back to original

function whichradio(){ // check for a selected radio button
formfield=document.f1.rad // formname and input names to be checked
if (formfield[i].checked==true){ // identify selected radio button
itext.innerText=("You have chosen radio button "+formfield[i].value) // show result

<form name=f1>
<input type=radio name=rad value=one onclick="whichradio()">one
<input type=radio name=rad value=two onclick="whichradio()">two
<input type=radio name=rad value=three onclick="whichradio()">three
<input type=radio name=rad value=four onclick="whichradio()">four
<P id=itext>Which one will you choose?
<P><input type=button value=Reset onclick="resetAll()">

07-26-2002, 08:13 AM
Thanks for the response but it doesn't quite cover what I need,

What I'm trying to do is if the value of the field I'm getting from my database is say, "YES" I want the relating radio button to be selected when I first go into the page,

Is this possible?



07-26-2002, 08:42 AM
yes, its possible, you have to write the radio button tags dynamically and add the selected attribute whenever the value matches your criteria, like:

<INPUT NAME="FiscalValue" TYPE="Radio" VALUE="0" <% if (Request.Cookies("leasedetails")("FiscalValue")==0){
<INPUT NAME="FiscalValue" TYPE="Radio" VALUE="15" <% if (Request.Cookies("leasedetails")("FiscalValue")==15){
%>CHECKED<%}%>>15 %<BR>
<INPUT NAME="FiscalValue" TYPE="Radio" VALUE="20" <% if (Request.Cookies("leasedetails")("FiscalValue")==20){
%>CHECKED<%}%>>20 %<BR>
<INPUT NAME="FiscalValue" TYPE="Radio" VALUE="25" <% if (Request.Cookies("leasedetails")("FiscalValue")==25){
%>CHECKED<%}%>>25 %<BR>

this is based on a cookie value, but you can change it to a field value of a record