Getting undefined from javascript array of arrays -
this linked previous question different , whole new question... have array, after nice php looks this:
var series = { "001":{ "game":"portal 2", "name":"portal 2" }, "002":{ "game":"minecraft", "name":"241" }, "003":{ "game":"minecraft", "name":"hackmine" }, "004":{ "game":"mass effect 3", "name":"mass effect 3" }, "005":{ "game":"league of legends", "name":"league of legends" }, "006":{ "game":"half life 2", "name":"the hidden: source" }, "007":{ "game":"skyrim", "name":"modded skyrim" } }
this bit populated fine... question when function called, gives game
, name
value undefined
function seriesidonblur() { var id = parseint(document.getelementbyid("series_id").value); if (series[id] == null) { var message = "the series id input invalid"; } else { var seriesid = series[id]; var game = seriesid['game']; var name = seriesid['name']; var message = "you've inputted id game: " + game + " series: " + name; } document.getelementbyid("series_id_check").innerhtml = message; }
you're shooting in foot leading 0
s: series['001']
not same series['1']
. either cut parseint
call (forcing user type '001'), drop leading 0s:
var series = { "1":{ "game":"portal 2", "name":"portal 2" }, ... "7":{ "game":"skyrim", "name":"modded skyrim" } }
or use array:
var series = [ { "game":"portal 2", "name":"portal 2" }, ... { "game":"skyrim", "name":"modded skyrim" } ]
Comments
Post a Comment