Jump to content

Select radio button to show 2 other radio button: HELP


Utech22

Recommended Posts

I have a radio button, that I want to use to show 2 others radio buttons, base on the radio option that the user selects;

 

 

 

This is what I have:

 


<?php 

$employeeArray = array('Employed','Unemployed');//define array



   if ( ($_POST['estatus'])  && $employeeArray[0] )//check condition

   {

##-------DISPLAY RADIO BUTTONS----------------------##

?> 

   <label>Employee: <input type="text" name="employee" maxlength="30" value="<?php echo $employee; ?>" /></label><br />         

  <label>Status: <?php

   foreach( $statusArray as $statusName )

   {

                     ?>   

                     <input type="radio" name="status" value="<?php echo $statusName; ?>" />

                     <?php echo $statusName; ?></label>

                     <?php 

    }

              ?>           

              <br /><br />

  <?php

         }else{}

  ?>

 

 

 

When the user selects the employed radio button the Employee and Status radio buttons should be display. else if unemployed radio button is selected don't show the other radio buttons;

 

U can use javascript for that. Use smth like this in the onclik method of the radio button:

 

if(this.selectedIndex == 0){
     radio1.style.display = 'block';
     radio2.style.display = 'none';
} elseif(this.selectedIndex == 1){
     radio1.style.display = 'none';
     radio2.style.display = 'block';
}

 

I dont know much about javascript but that should work. You can work out a function for that, using document.getElementById('radio1') instead of simply calling its id.

or maybe u can make it smth like onclick="window.location = 'yourpage.php?selected=option1';" (if it works as im not sure) and then use php for the rest of the thing, but still ure using javascript. It would be a lot easier attemping a pure javascript approach to this.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.