PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<input name="male" type="radio" value="male"> Male
<input name="female" type="radio" value="female"> Female
In the above code,both the radio buttons are getting selected!!
How to make sure that only one radio button can be selected?
I mean without javascript.
Also,I want to ensure that only one button is selected initially by default.But when I click the other button,the default button gets de-selected.
How to do that?
Is it possible without invoking javascript?(Bcz,I dont know javascript!!! )
To select one among multiple radio buttons, you need to set there 'name' attribute same ie. eg. make name=''gender' for both the radio buttons and check the results. and to get default selected value, provide the attribute ' checked'.
Yes,I have done as you have said.Default checked is 'Male'.
But when I select 'Female',after that it the output is always coming as 'Female" !!!
My re-written code is:
That is because of your if block conditions which were always executing both the blocks as $_POST['gender'] is always set and the php variable $gender is always having the final value set as 'Female'. Modify that patch with the following to get the required results.