Higeath
Higeath

Reputation: 109

Associative array with space in name doesn't appear

Those are the values i use to fill out a form:

var champions = {
    "Azir":["Shurima's Legacy","Conquering Sands","Arise!","Shifting Sands", "Emperor's Divide"],
    "Dr. Mundo":["Shurima's Legacy","Conquering Sands","Arise!","Shifting Sands", "Emperor's Divide"]
    };

The problem is with space instead of Dr. Mundo it shows as Dr. is there anyway to fix this problem?

Update:

echo '<input class="champion" type="text" list="champions" placeholder="Champion '.$i.'" name="champno[]" required autofocus><br/>
                            <datalist id="champions"></datalist>';

Jquery:

for(var key in champions){
            if(champions.hasOwnProperty(key)){
                $('#champions').append('<option value=' + key + '>');
            }
        }

Upvotes: 1

Views: 141

Answers (1)

shawn
shawn

Reputation: 4363

quote the value:

for(var key in champions){
        if(champions.hasOwnProperty(key)){
            $('#champions').append('<option value="' + key + '">');
        }
    }

or, you should use something like this (for a demo, not tested):

$('#champions').append($('<option>').attr('value', key));

Upvotes: 3

Related Questions