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; Quote 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. Quote 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; Quote 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. Quote 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 Quote 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. Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.