I never used radio button. Now I need to add radio button in my webpage. Radio button 1 is mother and radio button 2 is child. Is it in my database it is only 1 field or separate field one for mother and one for child?
Well… If there are two conditions here, one being mother, the other being child, then it would be logical to use ONE field (e.g. value = 0 = mother, value = 1 = child).
Here is some simple code for a form with two radio buttons in it:
I used it but how can I make sure that if the user choose the mother it would save in the database?and if the mother is already choose the child would not be clickable
All of the radio buttons in a group are clickable EXCEPT for the one already selected. Clicking on any of the others will change which one is selected.
With a radio button group there is only one field regardless of whether there are two buttons or two thousand buttons. The buttons just select what value to put in the field.
So with those two radio buttons and mother already selected the only clickable button is child. If it is clicked then it will be selected and not clickable and mother will be unselected and clickable.
Doing that would make each radio button a separate group of one and therefore invalid since you must have at least two radio buttons per group. The code you have there is more appropriate for checkboxes where each checkbox is a separate field.
With radio buttons you have one field per group of buttons and each button just supplies a different value.
Once the form is submitted the radio button group is no different from an ordinary input field and can be processed the same way. The only difference is that the only values you expect the field to have are those of the buttons in the group.
That is dependent on what values you use with the buttons. If you use numbers as the values then you can use a integer field. If you use text then char or varchar.