<?php
include "phpheader.inc";
?>

<?php
//DATASET
$states_array = array("AL"=>"Alabama","AK"=>"Alaska","AZ"=>"Arizona","AR"=>"Arkansas","CA"=>"California"
"CO"=>"Colorado","CN"=>"Conneticiut","DE"=>"Delaware","FL"=>"Florida","GA"=>"Georgia"
"HI"=>"Hawaii","ID"=>"Idaho","IL"=>"Illinois","IN"=>"Indiana","IA"=>"Iowa","KS"=>"Kansas"
"KY"=>"Kentucky","LA"=>"Louisiana","ME"=>"Maine","MD"=>"Maryland","MA"=>"Massachusettes","MI"=>"Michigan","MN"=>"Minnesota","MS"=>"Mississippi","MO"=>"Missouri","MT"=>"Montana","NE"=>"Nebraska"
"NV"=>"Nevada","NH"=>"New Hampshire","NJ"=>"New Jersey","NM"=>"New Mexico","NY"=>"New York"
"NC"=>"North Carolina","ND"=>"North Dakota","OH"=>"Ohio","OK"=>"Oklahoma","OR"=>"Oregon"
"PA"=>"Pennsylvania","RI"=>"Rhode Island","SC"=>"South Carolina","SD"=>"South Dakota"
"TN"=>"Tennessee","TX"=>"Texas","UT"=>"Utah","VA"=>"Virginia","VT"=>"Vermont","WA"=>"Washington","WV"=>"West Virginia""WI"=>"Wisconsin","WY"=>"Wyoming","DC"=>"District of Columbia","AB"=>"Alberta","BC"=>"British Columbia""MB"=>"Manitoba","NB"=>"New Brunswick","NF"=>"New Foundland","NS"=>"Nova Scotia","NT"=>"Northwest Territory""ON"=>"Ontario","PE"=>"Prince Edward Island","QC"=>"Quebec","SK"=>"Saskatchewan","YT"=>"Yukon Territory");
?>

<h2 class="center">Week 2 - Exercise 2</h2>
<p>This function accepts two parameters, the first (required) is a <b>field name</b> the second (optional) is the <b>default value</b> in the form of a valid United States/Canadian state abbreviation. The function generates an HTML &lt;SELECT&gt; box for US &amp; Canadian states, the 'name' parameter of the &lt;SELECT&gt; is set to the field name paramerter passed to the function and the default value is set to 'selected' within the construct.</p>


<form action="2exercise2.php" method="get">
<input type="hidden" name="ok" value="1" />

<?php
if(!(IsSet($ok))) {
?>
<div class="center">
<p class='navy'>You get to pick the <strong>default state</strong> and the select box <strong>name</strong>.</p></div>
<pre>Enter a <strong>two letter</strong> state abbreviation: <input type='text' name='select_state' /></pre>
<pre>Enter a <strong>name</strong> for this select list:     <input type='text' name='select_name' /></pre>
<div class="center"><input type='submit' /> <input type='reset' /></div>

<?php
}//end isset for first part of form
?>

<?php
if($ok==1) {
make_select($states_array$select_name$select_state);
}
//end ok

function make_select($states_array$select_name$select_state) {
    if(
$select_name == "") {
        echo(
"<p class='red' width='100'><strong>You need a Select List Name!</strong>&nbsp;&nbsp;&nbsp;<strong>You need a Select List Name!</strong>&nbsp;&nbsp;&nbsp;<strong>You need a Select List Name!</strong></p>");
        echo(
"<p><a href='2exercise2.php'>Try Again</a></p>");
        break;
    }
//end if
    
else {
        echo(
"<div class='center'><select name='$select_name' />");
        
reset($states_array);
        while(
$returned_array each($states_array)) {
            
$current_value $returned_array['value'];
            
$current_key $returned_array['key'];
            
$select_state strtoupper($select_state);
                if(
$current_key == $select_state) {
                    echo(
"<option selected>$current_value</option>");
                }
//end if for select state
                
else {
                    echo(
"<option>$current_value</option>");
                }
//end else to print most states
        
}//end while
    
echo("</select></div>");
    }
//end main else
}//end function
?>
</form>
<div class="center">
<br /><br /><br /><br />
<p><a href="php_content.php"><span class="navy">Back to Index of Assignments</span></a></p>
</div>
</body>
</html>