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? Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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> Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted January 14, 2007 Share Posted January 14, 2007 understand or need explanation?Ted Quote Link to comment 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? Quote Link to comment 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! Quote Link to comment 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> Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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> Quote Link to comment 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] Quote Link to comment Share on other sites More sharing options...
Pi_Mastuh Posted January 14, 2007 Author Share Posted January 14, 2007 Ah I see, thank you. Quote Link to comment 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.