完全な状態名をhtmlドロップダウンの短い値に変換するcaseステートメントを設定します。(はい、冗長に見えますが、複数のデータセットが入ってくるので必須でした)
これが私のケースステートメントです
var state_switch;
//document.write(temp[1]);
var state_case = temp[1];
//document.write("state =");
//document.write(state_case);
switch (state_case)
{
case "Alabama":
state_switch="AL";
break;
case "Alaska":
state_switch="AK";
break;
case "Arizona":
state_switch="AZ";
break;
case "Arkansas":
state_switch="AK";
break;
case "California":
state_switch="CA";
break;
case "Colorado":
state_switch="CO";
break;
case "Connecticut":
state_switch="CT";
break;
case "Delaware":
state_switch="DE";
break;
case "District of Columbia":
state_switch="DC";
break;
case "Florida":
state_switch="FL";
break;
case "Geogia":
state_switch="GA";
break;
case "Hawaii":
state_switch="HI";
break;
case "Idaho":
state_switch="ID";
break;
case "Illinois":
state_switch="IL";
break;
case "Indiana":
state_switch="IN";
break;
case "Iowa":
state_switch="IA";
break;
case "Kansas":
state_switch="KS";
break;
case "Kentucky":
state_switch="KY";
break;
case "Louisiana":
state_switch="LA";
break;
case "Maine":
state_switch="MA";
break;
case "Maryland":
state_switch="MD";
break;
case "Massachusetts":
state_switch="MA";
break;
case "Michigan":
state_switch="MI";
break;
case "Minnesota":
state_switch="MN";
break;
case "Mississippi":
state_switch="MS";
break;
case "Missouri":
state_switch="MO";
break;
case "Montana":
state_switch="MT";
break;
case "Nebraska":
state_switch="NE";
break;
case "Nevada":
state_switch="NE";
break;
case "New Hampshire":
state_switch="NH";
break;
case "New Jersey":
state_switch="NJ";
break;
case "New Mexico":
state_switch="NM";
break;
case "New York":
state_switch="NY";
break;
case "North Carolina":
state_switch="NC";
break;
case "North Dakota":
state_switch="ND";
break;
case "Ohio":
state_switch="OH";
break;
case "Oklahoma":
state_switch="OK";
break;
case "Oregon":
state_switch="OR";
break;
case "Pennsylvania":
state_switch="PA";
break;
case "Rhode Island":
state_switch="RI";
break;
case "South Carolina":
state_switch="SC";
break;
case "South Dakota":
state_switch="SD";
break;
case "Tennessee":
state_switch="TN";
break;
case "Texas":
state_switch="TX";
break;
case "Utah":
state_switch="UT";
break;
case "Vermont":
state_switch="VT";
break;
case "Virginia":
state_switch="VA";
break;
case "Washington":
state_switch="WA";
break;
case "West Virginia":
state_switch="WV";
break;
case "Wisconsin":
state_switch="WI";
break;
case "Wyoming":
state_switch="WY";
break;
default:
state_switch='';
}
//document.write("switch - ");
//document.write(state_switch);
if(me.location.name){
$("#state").val(state_switch);
}
これが私のドロップダウンです
<select name="state" id="state" class="short" style="margin-right:10px">
<option value=""></option>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="DC">District of Columbia</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="HI">Hawaii</option>
<option value="ID">Idaho</option>
<option value="IL">Illinois</option>
<option value="IN">Indiana</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NV">Nevada</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NM">New Mexico</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="ND">North Dakota</option>
<option value="OH">Ohio</option>
<option value="OK">Oklahoma</option>
<option value="OR">Oregon</option>
<option value="PA">Pennsylvania</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="SD">South Dakota</option>
<option value="TN">Tennessee</option>
<option value="TX">Texas</option>
<option value="UT">Utah</option>
<option value="VT">Vermont</option>
<option value="VA">Virginia</option>
<option value="WA">Washington</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
</select>
上記でコメントアウトされたプリントアウトをテストして実行しましたが、取得したデータは正しいものです。デフォルト値を「IL」に変更すると、ドロップダウンにイリノイが表示されます。ただし、それがstate_caseの値である場合、「イリノイ」はキャッチされません。