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 8 of 8

Thread: Radio Buttons

  1. #1
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts

    Radio Buttons

    I know this is extremely easy and I have no idea why it's not working correctly. I want 2 radio buttons on my page, and want it where the user can only select one of them. So if you click another, the first one goes blank. Well right now if you can select both at you can't un-select them. Below is my code. I am using it in PHP, and the way it's setup is how it has to run in my coding (with the slashes).

    Code:
    <table width='30%'>
            <tr><td>Test 1</td><td><INPUT TYPE=radio NAME=\"test1\" VALUE=\"Test1\" CHECKED></td><td>Test 2</td><td><INPUT TYPE=radio NAME=\"test2\" VALUE=\"Test 2\"></td></tr>
            </table>

  • #2
    New to the CF scene
    Join Date
    Feb 2008
    Posts
    9
    Thanks
    0
    Thanked 2 Times in 2 Posts
    They both have to have the same NAME value, that's what ties them together. Then, they need to have a different VALUE, which is what makes them different.

    Pete

  • #3
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Ah I see. But if they have the same name, won't that submit the same thing?

    Like for a example. Submitting a Name or an Age. A radio button for name, and another for age. But you only want to display one of them. Wouldn't both be the same output?

  • #4
    New to the CF scene
    Join Date
    Feb 2008
    Posts
    9
    Thanks
    0
    Thanked 2 Times in 2 Posts
    No, that's what the VALUE item is for.

    I'm not quite sure what you are trying to do here, but basically the NAME reference in forms directs your input to a certain location - like a particular field in a database. It sounds like you are trying to POST some information with these radios.

    <input type=radio name="field1" value="name" />
    <input type=radio name="field1" value="age" />

    This code will post either name or age into a field called "field1".

    Or, am I off in left field?

    Pete

  • Users who have thanked digipete for this post:

    masterofollies (02-27-2008)

  • #5
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Right, in the database I have 2 fields, we'll call them name and age as an example for now.

    I am just throwing general information out here.

    Let's say you have 2 text boxes like this

    Name: [ ] Age: [ ]

    then you have 2 radio buttons. Like this

    Name O Age O

    [SUBMIT]


    So you type in a either a name, or an age, and you select the radio button for which one you actually want to send. So if you type in age 24 and click the age radio button and submit, it updates the Age field in the database to that number.

  • #6
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Just an update, I got it all working.

  • #7
    New to the CF scene
    Join Date
    Feb 2008
    Posts
    9
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Cool, glad you got it to work.

    Just one more thought - make sure you make your instructions on that form clear. Chrystal clear, for that matter.

    Some people are pretty good at breezing their way through forms on autopilot. It sounds like it's important that the text field and radio buttons to match.

    Good luck.
    Pete

  • #8
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Ok will do, thanks


  •  

    Posting Permissions

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