View Full Version : Radio Buttons
02-27-2008, 12:50 AM
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).
<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>
02-27-2008, 01:10 AM
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.
02-27-2008, 01:33 AM
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?
02-27-2008, 02:05 AM
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?
02-27-2008, 02:27 AM
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
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.
02-27-2008, 04:34 AM
Just an update, I got it all working.
02-27-2008, 04:45 AM
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.
02-27-2008, 03:39 PM
Ok will do, thanks
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.