...

View Full Version : Value of a Radio List



NICKGE1
07-25-2002, 01:59 PM
Hi,

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

<script>
function resetAll(){ //checks to see if any radio buttons are selected
formfield=document.f1.rad // formname and input names to be checked
for(i=0;i<formfield.length;i++)
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
itext.style.color=""
itext.style.fontWeight=""
}
}

function whichradio(){ // check for a selected radio button
formfield=document.f1.rad // formname and input names to be checked
for(i=0;i<formfield.length;i++)
if (formfield[i].checked==true){ // identify selected radio button
itext.innerText=("You have chosen radio button "+formfield[i].value) // show result
itext.style.color="black"
itext.style.fontWeight="bold"
}
}
</script>


<form name=f1>
<P>
<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()">
</form>

NICKGE1
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?

Thanks

Nick

Roelf
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){
%>CHECKED<%}%>>None<BR>
<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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum