i know question on here alot, i'm not understanding why getting error end result want. here function:
function populate(){
for(var = 0; < locations.length; += 1){ var select = document.getelementbyid("end"); select.options[select.options.length] = new option(buildings[i][0], buildings[i][3]); } }; it pulls in array:
buildings = [ ['allied health', '', 'buildings', '35.206815, -101.908493', 2, "http://www.actx.edu/staff/images/icons/ac.png"], ['building a', '', 'buildings', '35.206718, -101.906127', 3, "http://www.actx.edu/staff/images/icons/ac.png"], ['building b', '', 'buildings', '35.207614, -101.907383', 4, "http://www.actx.edu/staff/images/icons/ac.png"], ['building c', '', 'buildings', '35.207545, -101.905702', 5, "http://www.actx.edu/staff/images/icons/ac.png"], ['building d', '', 'buildings', '35.207408, -101.906485', 6, "http://www.actx.edu/staff/images/icons/ac.png"], ['child development center', '', 'buildings', '35.207409, -101.908901', 7, "http://www.actx.edu/staff/images/icons/ac.png"], ['gymnastics/dance', '', 'buildings', '35.207264, -101.909682', 8, "http://www.actx.edu/staff/images/icons/ac.png"], ['jones hall', '', 'buildings', '35.207514, -101.908236', 9, "http://www.actx.edu/staff/images/icons/ac.png"], ['lecture hall', '', 'buildings', '35.206754, -101.907246', 10, "http://www.actx.edu/staff/images/icons/ac.png"], ['n.w. library', '', 'buildings', '35.206543, -101.904580', 11, "http://www.actx.edu/staff/images/icons/ac.png"], ['delta building', '', 'buildings', '35.208272, -101.905817', 12, "http://www.actx.edu/staff/images/icons/ac.png"] ]; and populates onload:
<body onload="populate();"> <select class="form-control" id="end" onchange="calcroute();"> <option disabled selected> -- select destination -- </option> </select> and want do, put building name , coordinates select box. error in console on chrome: uncaught typeerror: cannot read property '0' of undefined , points line:
select.options[select.options.length] = new option(buildings[i][0], buildings[i][3]); i'm not sure why throws error in chromes console, still works intended. appreciated.
maybe i variable exceeding buildings lenght. instance, if have 20 locations , 15 buildings, when browser evaluates new option(buildings[15][0], buildings[15][3]) throws error.
edit: more specific, supposing have 15 buildings, our array have indexs 0 14, buildings[15] undefined. error comes from, trying read buildings[15][0] reading undefined[0].
you should post locations variable in order better response.
var buildings = [ ['allied health', '', 'buildings', '35.206815, -101.908493', 2, "http://www.actx.edu/staff/images/icons/ac.png"], ['building a', '', 'buildings', '35.206718, -101.906127', 3, "http://www.actx.edu/staff/images/icons/ac.png"], ['building b', '', 'buildings', '35.207614, -101.907383', 4, "http://www.actx.edu/staff/images/icons/ac.png"], ['building c', '', 'buildings', '35.207545, -101.905702', 5, "http://www.actx.edu/staff/images/icons/ac.png"], ['building d', '', 'buildings', '35.207408, -101.906485', 6, "http://www.actx.edu/staff/images/icons/ac.png"], ['child development center', '', 'buildings', '35.207409, -101.908901', 7, "http://www.actx.edu/staff/images/icons/ac.png"], ['gymnastics/dance', '', 'buildings', '35.207264, -101.909682', 8, "http://www.actx.edu/staff/images/icons/ac.png"], ['jones hall', '', 'buildings', '35.207514, -101.908236', 9, "http://www.actx.edu/staff/images/icons/ac.png"], ['lecture hall', '', 'buildings', '35.206754, -101.907246', 10, "http://www.actx.edu/staff/images/icons/ac.png"], ['n.w. library', '', 'buildings', '35.206543, -101.904580', 11, "http://www.actx.edu/staff/images/icons/ac.png"], ['delta building', '', 'buildings', '35.208272, -101.905817', 12, "http://www.actx.edu/staff/images/icons/ac.png"] ]; var locations = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,]; function populate() { for(var = 0; < locations.length; += 1){ var select = document.getelementbyid("end"); select.options[select.options.length] = new option(buildings[i][0], buildings[i][3]); } }; <body onload="populate();"> <select class="form-control" id="end" onchange="calcroute();"> <option disabled selected> -- select destination -- </option> </select> this code snippet shows talking (if open browser console should see same error , caused locations array being longer buildings).
var buildings = [ ['allied health', '', 'buildings', '35.206815, -101.908493', 2, "http://www.actx.edu/staff/images/icons/ac.png"], ['building a', '', 'buildings', '35.206718, -101.906127', 3, "http://www.actx.edu/staff/images/icons/ac.png"], ['building b', '', 'buildings', '35.207614, -101.907383', 4, "http://www.actx.edu/staff/images/icons/ac.png"], ['building c', '', 'buildings', '35.207545, -101.905702', 5, "http://www.actx.edu/staff/images/icons/ac.png"], ['building d', '', 'buildings', '35.207408, -101.906485', 6, "http://www.actx.edu/staff/images/icons/ac.png"], ['child development center', '', 'buildings', '35.207409, -101.908901', 7, "http://www.actx.edu/staff/images/icons/ac.png"], ['gymnastics/dance', '', 'buildings', '35.207264, -101.909682', 8, "http://www.actx.edu/staff/images/icons/ac.png"], ['jones hall', '', 'buildings', '35.207514, -101.908236', 9, "http://www.actx.edu/staff/images/icons/ac.png"], ['lecture hall', '', 'buildings', '35.206754, -101.907246', 10, "http://www.actx.edu/staff/images/icons/ac.png"], ['n.w. library', '', 'buildings', '35.206543, -101.904580', 11, "http://www.actx.edu/staff/images/icons/ac.png"], ['delta building', '', 'buildings', '35.208272, -101.905817', 12, "http://www.actx.edu/staff/images/icons/ac.png"] ]; var locations = [0, 0, 0, 0, 0, 0, 0, 0, 0,]; function populate() { for(var = 0; < locations.length; += 1){ var select = document.getelementbyid("end"); select.options[select.options.length] = new option(buildings[i][0], buildings[i][3]); } }; <body onload="populate();"> <select class="form-control" id="end" onchange="calcroute();"> <option disabled selected> -- select destination -- </option> </select> as can see second snippet works without giving error (just because trimmed part of locations array). suggest change
for(var = 0; < locations.length; += 1){ with
for(var = 0; < buildings.length; += 1){ in order show of buildings can see in (finally last) snippet:
var buildings = [ ['allied health', '', 'buildings', '35.206815, -101.908493', 2, "http://www.actx.edu/staff/images/icons/ac.png"], ['building a', '', 'buildings', '35.206718, -101.906127', 3, "http://www.actx.edu/staff/images/icons/ac.png"], ['building b', '', 'buildings', '35.207614, -101.907383', 4, "http://www.actx.edu/staff/images/icons/ac.png"], ['building c', '', 'buildings', '35.207545, -101.905702', 5, "http://www.actx.edu/staff/images/icons/ac.png"], ['building d', '', 'buildings', '35.207408, -101.906485', 6, "http://www.actx.edu/staff/images/icons/ac.png"], ['child development center', '', 'buildings', '35.207409, -101.908901', 7, "http://www.actx.edu/staff/images/icons/ac.png"], ['gymnastics/dance', '', 'buildings', '35.207264, -101.909682', 8, "http://www.actx.edu/staff/images/icons/ac.png"], ['jones hall', '', 'buildings', '35.207514, -101.908236', 9, "http://www.actx.edu/staff/images/icons/ac.png"], ['lecture hall', '', 'buildings', '35.206754, -101.907246', 10, "http://www.actx.edu/staff/images/icons/ac.png"], ['n.w. library', '', 'buildings', '35.206543, -101.904580', 11, "http://www.actx.edu/staff/images/icons/ac.png"], ['delta building', '', 'buildings', '35.208272, -101.905817', 12, "http://www.actx.edu/staff/images/icons/ac.png"] ]; function populate() { for(var = 0; < buildings.length; += 1){ var select = document.getelementbyid("end"); select.options[select.options.length] = new option(buildings[i][0], buildings[i][3]); } }; <body onload="populate();"> <select class="form-control" id="end" onchange="calcroute();"> <option disabled selected> -- select destination -- </option> </select>
Comments
Post a Comment