Click to See Complete Forum and Search --> : common list of states


D_J
06-02-2009, 05:46 PM
I have several forms that have select menus. The most common is a list of the full names of states with their abbreviations as option values.

Is there a way to have one file with this control so that I can include it on a variety of pages but at the same time have a different name for the object on different pages?

Thanks!

kender
06-03-2009, 01:37 AM
ayou can have a file like...

Includes.php
$statefull = array("Alaska","Alabama","Illinois","Indiana"...);
$stateabb = array("AK","AL","IL","IN"...);


Then in your page that calls it

include_once("Includes.php");
echo '
<select name="state">';
$i = 0;
while ($1 <= 49) {
echo '
<option value="'.$stateabb[$i].'">'.$statefull[$i].'</option>
$i++
}
echo '
</select>';

not tested, but should do what you need

Charles
06-03-2009, 07:31 AM
Better to keep your data as an associative array. That way things won't get out of whack when you make changes when the US eats Canada. See the PHP forum iff you have PHP. Otherwise post the question to the forum associated with the server side scripting that you do have.

D_J
06-04-2009, 04:06 PM
Thanks both. I am using PHP and figured out how to load the states into an array and instead of using while, I used foreach().