Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.