Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jul 2002
    Location
    Bounemouth (UK)
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Value of a Radio List

    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

  • #2
    New Coder
    Join Date
    Jul 2002
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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>

  • #3
    New to the CF scene
    Join Date
    Jul 2002
    Location
    Bounemouth (UK)
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    Zwolle, The Netherlands
    Posts
    1,120
    Thanks
    2
    Thanked 31 Times in 31 Posts
    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
    Last edited by Roelf; 07-26-2002 at 09:45 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •