Pi_Mastuh Posted January 14, 2007 Share Posted January 14, 2007 I want my select box to default to the option the user had specified in the past. It saves it and then it's a variable. So ho do I tell it to make the selected option the variable? Link to comment https://forums.phpfreaks.com/topic/34087-default-option-in-drop-down-how/ Share on other sites More sharing options...
fert Posted January 14, 2007 Share Posted January 14, 2007 put[code]selected[/code]in the option tag and I believe it will be selected Link to comment https://forums.phpfreaks.com/topic/34087-default-option-in-drop-down-how/#findComment-160245 Share on other sites More sharing options...
Pi_Mastuh Posted January 14, 2007 Author Share Posted January 14, 2007 But i can't just put selected in because the selected one will need to bbe different for different users. Somehow I need to tell it to select the one that's the same as the variable. Link to comment https://forums.phpfreaks.com/topic/34087-default-option-in-drop-down-how/#findComment-160246 Share on other sites More sharing options...
ted_chou12 Posted January 14, 2007 Share Posted January 14, 2007 <?php function select($pm, $type){if ($pm == $type) echo "selected=\"selected\"";}?><option value="pm.php?pm=inbox" <?php select($pm, "inbox");?>>Inbox</option> Link to comment https://forums.phpfreaks.com/topic/34087-default-option-in-drop-down-how/#findComment-160249 Share on other sites More sharing options...
ted_chou12 Posted January 14, 2007 Share Posted January 14, 2007 understand or need explanation?Ted Link to comment https://forums.phpfreaks.com/topic/34087-default-option-in-drop-down-how/#findComment-160250 Share on other sites More sharing options...
Pi_Mastuh Posted January 14, 2007 Author Share Posted January 14, 2007 I don't see what I put where exactly. I'm working with an avatar selection thing for forums so the variable I'm using is $avatar. Where does that go? Link to comment https://forums.phpfreaks.com/topic/34087-default-option-in-drop-down-how/#findComment-160253 Share on other sites More sharing options...
ted_chou12 Posted January 14, 2007 Share Posted January 14, 2007 $pm, is what you stored as the variable in your mysql database, and $type is the specific value for that selection, so when the stored data equals the selection, echo select! Link to comment https://forums.phpfreaks.com/topic/34087-default-option-in-drop-down-how/#findComment-160254 Share on other sites More sharing options...
ted_chou12 Posted January 14, 2007 Share Posted January 14, 2007 one more example then:<?php function select($pm, $type){if ($pm == $type) echo "selected=\"selected\"";}?><option value="inbox" <?php select($pm, "inbox");?>>Inbox</option><option value="outbox" <?php select($pm, "outbox");?>>Outbox</option>regular would look this:<option value="xx" selected="selected">Standard</option><option value="thumbup">Thumb Up</option> Link to comment https://forums.phpfreaks.com/topic/34087-default-option-in-drop-down-how/#findComment-160255 Share on other sites More sharing options...
Pi_Mastuh Posted January 14, 2007 Author Share Posted January 14, 2007 So I would have: [code]<select name='avatar'><?php function select($avatar, $type){if ($avvie == $type) echo "selected=\"selected\"";}?><option value="avatar.php?avatar=avatar1" <?php select($avatar, "avatar1");?>>avatar1</option><option value="avatar.php?avatar=avatar2" <?php select($avatar, "avatar2");?>>avatar2</option><option value="avatar.php?avatar=avatar3" <?php select($avatar, "avatar3");?>>avatar3</option>[/code]etc? Link to comment https://forums.phpfreaks.com/topic/34087-default-option-in-drop-down-how/#findComment-160260 Share on other sites More sharing options...
ted_chou12 Posted January 14, 2007 Share Posted January 14, 2007 [code]<select name='avatar'><?php function select($avatar, $type){if ($avatar == $type) echo "selected=\"selected\"";}?><option value="avatar1" <?php select($avatar, "avatar1");?>>avatar1</option><option value="avatar2" <?php select($avatar, "avatar2");?>>avatar2</option><option value="avatar3" <?php select($avatar, "avatar3");?>>avatar3</option>[/code]avatar1 is your value, and $type is your data so this is correct.sorry to confuse you with the pm.php?pm=inbox I should have use it to fit your eg. at first... :-\Ted Link to comment https://forums.phpfreaks.com/topic/34087-default-option-in-drop-down-how/#findComment-160261 Share on other sites More sharing options...
Pi_Mastuh Posted January 14, 2007 Author Share Posted January 14, 2007 Ok, so what I want to do is store URLs. WOuld that be the value then?<option value='http://www.net-petz.com/images/avvies/Default_av.jpg'<?php select($avvie, "Default");?>>Default</option> Link to comment https://forums.phpfreaks.com/topic/34087-default-option-in-drop-down-how/#findComment-160262 Share on other sites More sharing options...
ted_chou12 Posted January 14, 2007 Share Posted January 14, 2007 then you would also need to change the other value:[code]<select name='avatar'><?php function select($avatar, $type){if ($avatar == $type) echo "selected=\"selected\"";}?><option value="http://www.net-petz.com/images/avvies/Default_av1.jpg" <?php select($avatar, "http://www.net-petz.com/images/avvies/Default_av1.jpg");?>>avatar1</option><option value="http://www.net-petz.com/images/avvies/Default_av2.jpg" <?php select($avatar, "http://www.net-petz.com/images/avvies/Default_av2.jpg");?>>avatar2</option><option value="http://www.net-petz.com/images/avvies/Default_av3.jpg" <?php select($avatar, "http://www.net-petz.com/images/avvies/Default_av3.jpg");?>>avatar3</option>[/code] Link to comment https://forums.phpfreaks.com/topic/34087-default-option-in-drop-down-how/#findComment-160263 Share on other sites More sharing options...
Pi_Mastuh Posted January 14, 2007 Author Share Posted January 14, 2007 Ah I see, thank you. Link to comment https://forums.phpfreaks.com/topic/34087-default-option-in-drop-down-how/#findComment-160265 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.