Jump to content

[SOLVED] PHP and HTML Select Forms


llDemonll

Recommended Posts

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

<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>

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

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?

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.