jamesjmann Posted December 30, 2011 Share Posted December 30, 2011 I know this is probably going to sound like a stupid question, but I have a multiple select box with this code: <select MULTIPLE> </select> And a foreach statement that dynamically generates <option>'s. I want one option to be automatically selected when the user clicks the page, depending on a certain $_GET variable in the query string. I tried: <option SELECTED> Like you would a normal <select> and this didn't work. Anyone know if this is even possible? Note: I tried googling it, but google turned up nothing. Someone help. I'm a newb at multiple selects lol. Quote Link to comment https://forums.phpfreaks.com/topic/254064-multiple-selectbox-select-attribute/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 30, 2011 Share Posted December 30, 2011 Following works for me - <form action="formaction.php"> <select multiple="multiple" name="cars[]"> <option value="volvo">Volvo</option> <option value="saab">Saab</option> <option value="opel" selected="selected">Opel</option> <option value="audi">Audi</option> </select> <input type="submit" /> </form> Are you sure you output the correct syntax in your actual form? Quote Link to comment https://forums.phpfreaks.com/topic/254064-multiple-selectbox-select-attribute/#findComment-1302452 Share on other sites More sharing options...
jamesjmann Posted December 30, 2011 Author Share Posted December 30, 2011 Nevermind. After looking at my code I realized I forgot to add a space in between "<option" and "SELECTED". Quote Link to comment https://forums.phpfreaks.com/topic/254064-multiple-selectbox-select-attribute/#findComment-1302453 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.