thanks,
 no idea how I missed that, I certainly know better

Lukas Pitschl | Dressy Vagabonds wrote:
Hi Charlie,

If you check your code, you'll see that you're not quoting your stateName value,
hence the html code for your North Carolina option looks like this.

<option value=North Carolina>NC</option>

what you want though, is to use quotes with the value so the output looks like this

<option value="North Carolina">NC</option>

You have to change your js code to this

$("#job_state").append("<option value=\"" +stateName + "\">" +stateAbbr + "</option>");

Best regards,

Lukas

Am 10.12.2009 um 13:55 schrieb Charlie:

  
Creating a set of dropdowns for US states as follows:

$.getJSON("../js/stateListJSON.txt",function(data){
        $(data.statelist).each( function(i) {
                var stateAbbr = data.statelist[i].state;
                var stateName = data.statelist[i].name;
                $("#job_state").append("<option value=" +stateName + ">" +stateAbbr + "</option>");
        });
});

JSON excerpt
{"state":"MT","name":"Montana"},{"state":"NC","name":"North Carolina"}

HTML Output:
Single word states all append fine but 2 word states get inserted as:

<option carolina="" value="North">NC</option>

Using more efficient method of creating one string in the $.each and appending the whole string once after $each, or using $("#job_state").html(completeOptionString)  resulted in same problem.
Only solution I found was append the option tags with no value and add the value using $("#job_state option:last").val(stateName)

What would cause the split of the 2 words and an attribute   carolina=""  to be created?
    


  

Reply via email to