1

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 + '>');
            }
        }
4
  • 2
    What "it" shows? JS does not care what characters form the key as soon as it's a string. Commented Jun 8, 2015 at 11:20
  • 1
    This seems to be working correctly for me - perhaps the issue is with some other part of the code you are using? Could you please add some context? Commented Jun 8, 2015 at 11:23
  • What you've provided in your update is not even JS (but php). Commented Jun 8, 2015 at 11:26
  • This works for(var key in champions){ console.log(key) }... if you have that string as a json, then decoded it in php and iterate through it to get it's key name. Should work. Commented Jun 8, 2015 at 11:28

1 Answer 1

3

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));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.