Jump to content

preselected radio button


jimfog
 Share

Recommended Posts

I have made a form where some radio buttons are contained.The selection made by the user is stored in the db tables as a number, corresponding to the different values of each of the radio buttons. Here are the radio buttons with corresponding values:

<td><input type="radio" class="formBuzType" name="buztype" value="1" > <label>test1</label><br></td>					  <td> <input type="radio" class="formBuzType" name="buztype" value="3"> <label>test3</label> <br></td>					  <td> <input type="radio" class="formBuzType"  name="buztype" value="4"> <label>test4</label>  <br></td>					  <td><input type="radio" class="formBuzType" name="buztype" value="5"> <label>test5</label> <br></td>					  <td><input type="radio"  class="formBuzType"    name="buztype" value="2"><label>test2</label> <br></td>					  

If the user has chosen test3 then "3" will be stored in the database. Getting the value 3 from the db is not difficult(a simple SELECT query)...what I cannot do is making the appropriate preselection in the form depending on the fetched from the db value. To say it simpler...since 3 is in the db, I want when the radio buttons appear to the user(HTML) the value 3 option is selected so that the user can know what he has chosen the last time...how I will do that?

Link to comment
Share on other sites

Have a line of PHP inside the markup for each radio button to check the radio button's value against the value from the database. If it matches then print the attribute to select the button.
That is what I thought to.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...