Utech22 Posted August 5, 2007 Share Posted August 5, 2007 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; Link to comment https://forums.phpfreaks.com/topic/63438-select-radio-button-to-show-2-other-radio-button-help/ Share on other sites More sharing options...
Fadion Posted August 5, 2007 Share Posted August 5, 2007 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. Link to comment https://forums.phpfreaks.com/topic/63438-select-radio-button-to-show-2-other-radio-button-help/#findComment-316170 Share on other sites More sharing options...
Utech22 Posted August 5, 2007 Author Share Posted August 5, 2007 I am running away from js. I want to validate it using php; Link to comment https://forums.phpfreaks.com/topic/63438-select-radio-button-to-show-2-other-radio-button-help/#findComment-316252 Share on other sites More sharing options...
Fadion Posted August 5, 2007 Share Posted August 5, 2007 Guess theres no way to display data on the fly without javascript. Why not use it anyway, most users have it enabled. Link to comment https://forums.phpfreaks.com/topic/63438-select-radio-button-to-show-2-other-radio-button-help/#findComment-316259 Share on other sites More sharing options...
teng84 Posted August 5, 2007 Share Posted August 5, 2007 theres no way to obtain that without JS or AJAX but you can have the onclick property of radio button something like onclick='Javascript:document.submit()' something like that Link to comment https://forums.phpfreaks.com/topic/63438-select-radio-button-to-show-2-other-radio-button-help/#findComment-316262 Share on other sites More sharing options...
Fadion Posted August 5, 2007 Share Posted August 5, 2007 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. Link to comment https://forums.phpfreaks.com/topic/63438-select-radio-button-to-show-2-other-radio-button-help/#findComment-316276 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.