Populate select form field via jquery
I have a form where a user may select a box from above which will query the database and autofill in the fields. This works properly for all of my input text fields but I have a select box where a user selects their state that I am unable to get to properly populate.
The select box is populated on page load in the following format....
- <select id="state" name="state">
- <option value="1">ALABAMA</option>
- <option value="2">ALASKA</option>
- </select>
etc...
The jquery code I utilize to populate my form fields is as follows...
- <script type="text/javascript">
- function getUserInfo(custid) {
- $.getJSON("cfc/UserTransactions.cfc",
- {
- method: "getUserData",
- customerid: custid,
- },
- function(data) {
- var columnMa
- for (var i = 0; i < data.COLUMNS.length; i++) {
- columnMap[data.COLUMNS[i]] = i
- }
- for (var i = 0; i < data.DATA.length; i++) {
- $("#first_name").val(data.DATA[i][columnMap.FIRST_NAME]);
- $("#last_name").val(data.DATA[i][columnMap.LAST_NAME]);
- $("#emailpayee").val(data.DATA[i][columnMap.EMAIL]);
- $("#phone").val(data.DATA[i][columnMap.PHONE]);
- $("#address1").val(data.DATA[i][columnMap.ADDRESS]);
- $("#address2").val(data.DATA[i][columnMap.ADDRESS2]);
- $("#city").val(data.DATA[i][columnMap.CITY]);
- $("#state").val(data.DATA[i][columnMap.STATEID]);
- $("#zipcode").val(data.DATA[i][columnMap.ZIP]);
- }
- }
- )};
- </script>
Everything populates correctly except where I try to set the val on the state select field. It does not change at all. I need it to display the statename with the value of the state (number). Thank you in advance for any help you can provide!