llDemonll Posted October 11, 2008 Share Posted October 11, 2008 So I'm making a website for a friend's company and they have a large list of retailers in a database and there's a single page that is used for maintaining the database, you can search for companies, can choose from a list of states, can edit, delete, and insert new companies from this page. Right now the page is set up in a text from input method, and my friend (and I) were wondering if I can set it up so that I can use a drop-down menu for states, and not manually have to type in the state name (some are hard to spell and remember, like massachussets (i think thats how you spell it)) and the state abbreviation. The drop down menu I am fine with, and making a function to insert the abbreviation based on which state is chosen is easy as well, the part I am stuck on is how to make it so that when I edit a state it will have the correct state "pre-selected" in the drop down menu when it fills out the form fields with the selected companies information. If needed I can send people the page I am speaking of, it's kinda big tho (and messy atm). Thanks much =) Link to comment https://forums.phpfreaks.com/topic/128028-solved-php-and-html-select-forms/ Share on other sites More sharing options...
AndyB Posted October 11, 2008 Share Posted October 11, 2008 Assuming your list of states is in an array (anything else is deranged), as you use php to loop through the array to generate the dropdown options, add select='selected' to the option value that matches the pre-selected state. Link to comment https://forums.phpfreaks.com/topic/128028-solved-php-and-html-select-forms/#findComment-662945 Share on other sites More sharing options...
llDemonll Posted October 11, 2008 Author Share Posted October 11, 2008 <select size="10" name="menu"> <option selected value="" >Select A State</option> <option value="New York">New York</option> <option value="California">California</option> <option value="Florida">Florida</option> <option value="Rhode Island">Rhode Island</option> </select> so something like that? (i pulled this off some site randomly) or does the select='selected' need to be in the top line like: <select='selected' size="10" name="menu"> <option value="" >Select A State</option> <option value="New York">New York</option> <option value="California">California</option> <option value="Florida">Florida</option> <option value="Rhode Island">Rhode Island</option> </select> Link to comment https://forums.phpfreaks.com/topic/128028-solved-php-and-html-select-forms/#findComment-662957 Share on other sites More sharing options...
AndyB Posted October 11, 2008 Share Posted October 11, 2008 You can't pull some html code randomly! The example below would have California 'pre-selected' in the dropdown <select size="10" name="menu"> <option selected value="" >Select A State</option> <option value="New York">New York</option> <option value="California" select='selected'>California</option> <option value="Florida">Florida</option> <option value="Rhode Island">Rhode Island</option> </select> I did say ... add select='selected' to the option value that matches the pre-selected state Link to comment https://forums.phpfreaks.com/topic/128028-solved-php-and-html-select-forms/#findComment-662958 Share on other sites More sharing options...
llDemonll Posted October 11, 2008 Author Share Posted October 11, 2008 the first select doesn't need to be there then? <option selected value="" >Select A State</option> the understanding i got from this was that i could just add 'selected' like that in the option tag and that one would be selected? or is there not a difference between doing it that way and <option value="California" select='selected'>California</option> that way? Link to comment https://forums.phpfreaks.com/topic/128028-solved-php-and-html-select-forms/#findComment-662964 Share on other sites More sharing options...
AndyB Posted October 11, 2008 Share Posted October 11, 2008 Oops, I didn't notice the first piece. The real code is: <select size="10" name="menu"> <option value="">Select A State</option> <option value="New York">New York</option> <option value="California" select='selected'>California</option> <option value="Florida">Florida</option> <option value="Rhode Island">Rhode Island</option> </select> Link to comment https://forums.phpfreaks.com/topic/128028-solved-php-and-html-select-forms/#findComment-662994 Share on other sites More sharing options...
llDemonll Posted October 12, 2008 Author Share Posted October 12, 2008 sweet - got it working thanks much for the help Link to comment https://forums.phpfreaks.com/topic/128028-solved-php-and-html-select-forms/#findComment-663219 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.