user3386541
user3386541

Reputation: 1

Radio button automatic change the data in php

I am new to php i am keeping 2 radio buttons one is checked default when page is loaded the content should be displayed for the radiobutton based content default

Upvotes: 0

Views: 108

Answers (4)

Nikunj Kabariya
Nikunj Kabariya

Reputation: 840

Consider below sample code for your better understanding:

<?php $value='male';?>
<input type="radio" name="gender" value="male"  <?php if($value=='male') echo 'checked="checked"'; ?>>Male<br>
<input type="radio" name="gender" value="female" <?php if($value=='female') echo 'checked="checked"'; ?>>Female

Upvotes: 0

xate
xate

Reputation: 6379

Some Tips and ideas to do that:

You load 2 different divs, 1 for each radio button.

1 is the default,

The other 1 is hidden, until somebody select the other radio button.

When the radio button is selected, u execute some javascript code.

Use

getELementbyId(IDofDIV)

to switch

display:hidden

to

display:block

Upvotes: 1

Shijin TR
Shijin TR

Reputation: 7756

I think this will help to understand,

   <?php
   $sex='male';
   ?>
  <input type="radio" name="sex" value="male"  <?php if($sex=='male') echo 'checked="checked"'; ?>>Male<br>
  <input type="radio" name="sex" value="female" <?php if($sex=='female') echo 'checked="checked"'; ?>>Female

Output

enter image description here

Upvotes: 1

Mritunjay kumar
Mritunjay kumar

Reputation: 19

**Use this:**

<fieldset>
    <legend>Gender:</legend>
        <input type="radio" name="gender" id="bloke" value="M">
    <label for="bloke">Male</label>
        <input type="radio" name="gender" id="sheila" value="F">
    <label for="sheila">Female</label>
</fieldset>

Upvotes: 0

Related Questions