Solarpitch Posted July 9, 2008 Share Posted July 9, 2008 Hi, I'm trying to make a selection in a Option Box based on a value of a variable. I have the variable $category that will store that value of a Manufacturer. So if it value is "Titleist", I want the option box to have that value selected <select name="select" style="width:254px; "> <option value="Callaway">Callaway</option> <option value="Ping" >Ping</option> <option value="Titleist" SELECTED>Ping</option> <option value="Cobra" >Ping</option> </select> Link to comment https://forums.phpfreaks.com/topic/113872-solved-select-box-php-result-question/ Share on other sites More sharing options...
bluejay002 Posted July 9, 2008 Share Posted July 9, 2008 an if() would do i suppose. Link to comment https://forums.phpfreaks.com/topic/113872-solved-select-box-php-result-question/#findComment-585156 Share on other sites More sharing options...
Solarpitch Posted July 9, 2008 Author Share Posted July 9, 2008 I thought about that but 1.) I'm not sure how you could use an if to select the right one and 2.) I'd probably have a tone of if's on my page Link to comment https://forums.phpfreaks.com/topic/113872-solved-select-box-php-result-question/#findComment-585160 Share on other sites More sharing options...
Brunda Posted July 9, 2008 Share Posted July 9, 2008 If your selected value is going to vary then you can use a variable and do it for eg. $var = 'pqr1'; if($var == 'pqr1'){ $selected = 'SELECTED'; }else{ $selected = ''; } <select name="abc" /> <option value="pqr" $selected> pqr </option> <option value="pqr1" $selected> pqr1 </option> <option value="pqr2" $selected> pqr2 </option> </select> this way you wouldn't have to have multiple if's and else's I hope this helps Link to comment https://forums.phpfreaks.com/topic/113872-solved-select-box-php-result-question/#findComment-585243 Share on other sites More sharing options...
Solarpitch Posted July 9, 2008 Author Share Posted July 9, 2008 That does help! Thanks a mill Link to comment https://forums.phpfreaks.com/topic/113872-solved-select-box-php-result-question/#findComment-585270 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.