Wayniac Posted June 30, 2010 Share Posted June 30, 2010 Hello everyone, Below I have a HTML code with a bit of PHP that is only calling its partners in crime so to speak. That is not the priority here, the edit code works fine for any textboxes that needs editing, but is not for the drop down boxes. Let me explain further... In a previous page, I will set the dropdown box to ex: Spring 2011, and that accepts correctly in the database. It even carries over fine with the example textbox I placed in the code below. But the dropdown box defaults to the first item in the list, which would be Fall 2010. Now I can change this and submit with either the example textbox or even the dropdown box and it will work, that is not the issue. My issue is that the dropdown box will not keep the value that is stored in the database, but the textbox example will. I will explain my idea I have for overcoming this... I was thinking if I use a hidden textbox to receive the value, and then somehow (my problem) have the dropdown box which has the same name as the textbox be set so it reads the textbox and changes to that value. Does anyone have an idea on how I can get this to work? Any thought on this topic would be a great asset to me finishing this dilemma. Here is the basic HTML code below... <select name="ship_season" class="textBox_center" id="ship_season" style="min-width:200px;" value="<?php echo $ship_season; ?>"> <option value="Fall 2010">Fall 2010</option> <option value="Spring 2010">Spring 2010</option> <option value="Fall 2011">Fall 2011</option> <option value="Spring 2011">Spring 2011</option> </select> <input name="ship_season" id="ship_season" value="<?php echo $ship_season; ?>"/> Thank you all so much. Quote Link to comment https://forums.phpfreaks.com/topic/206269-dropdown-box-edit-issue/ Share on other sites More sharing options...
phpology Posted June 30, 2010 Share Posted June 30, 2010 in your select list example you have added an attribute called value which does not work with select lists as its assigned to the option. if you want your option to be selected based on your db value you need to do an if-else within each option something along the lines of this <option value="Fall 2010" <?php if($ship_season == "Fall 2010") {echo " selected"; }?>>Fall 2010</option> <option value="Spring 2010"<?php if($ship_season == "Spring 2010") {echo " selected"; }?>>Spring 2010</option> <option value="Fall 2011"<?php if($ship_season == "Fall 2011") {echo " selected"; }?>>Fall 2011</option> <option value="Spring 2011"<?php if($ship_season == "Spring 2011") {echo " selected"; }?>>Spring 2011</option> if you were generating your selectlist options via a db then it would be a lot cleaner to be honest as then you dont have to hardcode each option like the above. hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/206269-dropdown-box-edit-issue/#findComment-1079165 Share on other sites More sharing options...
Wayniac Posted June 30, 2010 Author Share Posted June 30, 2010 Thank you so much, that worked 100% your so amazing! Quote Link to comment https://forums.phpfreaks.com/topic/206269-dropdown-box-edit-issue/#findComment-1079243 Share on other sites More sharing options...
phpology Posted June 30, 2010 Share Posted June 30, 2010 no worries dude Quote Link to comment https://forums.phpfreaks.com/topic/206269-dropdown-box-edit-issue/#findComment-1079244 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.