javascript - jquery dynamic dependent select from multidimensional array -


i trying have have form 2 drop down select options populated arrays. first select has 1 array, depending on selection, want populate second specific multidimensional array. able them individually, unable pass array name first selection function populate second.

i pretty new javascript , jquery 1.11.0 , appreciate assistance.

here code working with.

select name="aircraftlist" id="aircraftlist" onchange="showaircraft(this.selectedindex)"  select name="configwblist" id="configwblist"  // values aircraft // tnumber, acmodel, maxwt, f1arm, m1arm, r1arm, littarm, bag1max, fuel1kgmax,  ///////////////////////////////////////////////////////////  var aircraft = [     ["select aircraft", "", "", "", "", "", "", "", "", ""],     ['n901ah', "agusta a109e", 3000, 1585, 2455, 3200, 5300, 3200, 150, 480],     ['n902ah', "agusta a109e", 3000, 1585, 2455, 3200, 5300, 3200, 150, 480],     ['n903ah', "agusta a109e", 3000, 1585, 2455, 3200, 5300, 3200, 150, 480],     ['n904ah', "agusta a109e", 3000, 1585, 2455, 3200, 5300, 3200, 150, 480],     ['n905ah', "agusta a109e", 3000, 1585, 2455, 3200, 5300, 3200, 150, 480],     ['n907ah', "agusta a109e", 3000, 1585, 2455, 3200, 5300, 3200, 150, 480] ];  // values ac n901ah ///////////////////////////////////////////////////////////  var n901ah = [     ["select configuration", "select config", "select config"],     ["6 pax standard seats offshore", 2205.61, 3485.69],     ["dual controls installed", 2207.81, 3483.76],     ["vip seats installed", 2212.11, 3483.75],     ["vip seats, dual controls installed", 2214.31, 3481.83],     ["one litter kit installed", 2213.91, 3483.50],     ["one litter, dual controls installed", 2216.11, 3481.58],     ["6 pax standard seats, vests removed", 2196.81, 3489.83],     ["vip seats installed, vest removed", 2203.31, 3487.87],     ["one litter installed, vests removed", 2207.31, 3487.02],     ["two litter installed", 2222.21, 3481.32],     ["two litter, dual controls installed", 2224.41, 3479.41],     ["vip seats, dual controls installed, vests removed", 2205.51, 3485.93],     ["one litter, dual controls installed, vests removed", 2209.51, 3485.09],     ["two litter, dual controls installed, vests removed", 2220.01, 3482.33],     ["floats, raft, vests removed", 2084.51, 3507.26] ];  // values ac n902ah ///////////////////////////////////////////////////////////  var n902ah = [     ["select configuration", "select config", "select config"],     ["6 pax standard seats offshore", 2205.61, 3485.69],     ["dual controls installed", 2207.81, 3483.76],     ["vip seats installed", 2212.11, 3483.75],     ["vip seats, dual controls installed", 2214.31, 3481.83],     ["one litter kit installed", 2213.91, 3483.50],     ["one litter, dual controls installed", 2216.11, 3481.58],     ["6 pax standard seats, vests removed", 2196.81, 3489.83],     ["vip seats installed, vest removed", 2203.31, 3487.87],     ["one litter installed, vests removed", 2207.31, 3487.02],     ["two litter installed", 2222.21, 3481.32],     ["two litter, dual controls installed", 2224.41, 3479.41],     ["vip seats, dual controls installed, vests removed", 2205.51, 3485.93],     ["one litter, dual controls installed, vests removed", 2209.51, 3485.09],     ["two litter, dual controls installed, vests removed", 2220.01, 3482.33],     ["floats, raft, vests removed", 2084.51, 3507.26] ];  // values ac n903ah ///////////////////////////////////////////////////////////  var n903ah = [     ["select configuration", "select config", "select config"],     ["6 pax standard seats offshore", 2205.61, 3485.69],     ["dual controls installed", 2207.81, 3483.76],     ["vip seats installed", 2212.11, 3483.75],     ["vip seats, dual controls installed", 2214.31, 3481.83],     ["one litter kit installed", 2213.91, 3483.50],     ["one litter, dual controls installed", 2216.11, 3481.58],     ["6 pax standard seats, vests removed", 2196.81, 3489.83],     ["vip seats installed, vest removed", 2203.31, 3487.87],     ["one litter installed, vests removed", 2207.31, 3487.02],     ["two litter installed", 2222.21, 3481.32],     ["two litter, dual controls installed", 2224.41, 3479.41],     ["vip seats, dual controls installed, vests removed", 2205.51, 3485.93],     ["one litter, dual controls installed, vests removed", 2209.51, 3485.09],     ["two litter, dual controls installed, vests removed", 2220.01, 3482.33],     ["floats, raft, vests removed", 2084.51, 3507.26] ];  // values ac n904ah ///////////////////////////////////////////////////////////  var n904ah = [     ["select configuration", "select config", "select config"],     ["6 pax standard seats offshore", 2205.61, 3485.69],     ["dual controls installed", 2207.81, 3483.76],     ["vip seats installed", 2212.11, 3483.75],     ["vip seats, dual controls installed", 2214.31, 3481.83],     ["one litter kit installed", 2213.91, 3483.50],     ["one litter, dual controls installed", 2216.11, 3481.58],     ["6 pax standard seats, vests removed", 2196.81, 3489.83],     ["vip seats installed, vest removed", 2203.31, 3487.87],     ["one litter installed, vests removed", 2207.31, 3487.02],     ["two litter installed", 2222.21, 3481.32],     ["two litter, dual controls installed", 2224.41, 3479.41],     ["vip seats, dual controls installed, vests removed", 2205.51, 3485.93],     ["one litter, dual controls installed, vests removed", 2209.51, 3485.09],     ["two litter, dual controls installed, vests removed", 2220.01, 3482.33],     ["floats, raft, vests removed", 2084.51, 3507.26] ];  // values ac n905ah ///////////////////////////////////////////////////////////  var n905ah = [     ["select configuration", "select config", "select config"],     ["6 pax standard seats offshore", 2205.61, 3485.69],     ["dual controls installed", 2207.81, 3483.76],     ["vip seats installed", 2212.11, 3483.75],     ["vip seats, dual controls installed", 2214.31, 3481.83],     ["one litter kit installed", 2213.91, 3483.50],     ["one litter, dual controls installed", 2216.11, 3481.58],     ["6 pax standard seats, vests removed", 2196.81, 3489.83],     ["vip seats installed, vest removed", 2203.31, 3487.87],     ["one litter installed, vests removed", 2207.31, 3487.02],     ["two litter installed", 2222.21, 3481.32],     ["two litter, dual controls installed", 2224.41, 3479.41],     ["vip seats, dual controls installed, vests removed", 2205.51, 3485.93],     ["one litter, dual controls installed, vests removed", 2209.51, 3485.09],     ["two litter, dual controls installed, vests removed", 2220.01, 3482.33],     ["floats, raft, vests removed", 2084.51, 3507.26] ];  // values ac n907ah ///////////////////////////////////////////////////////////  var n907ah = [     ["select configuration", "select config", "select config"],     ["6 pax standard seats offshore", 2205.61, 3485.69],     ["dual controls installed", 2207.81, 3483.76],     ["vip seats installed", 2212.11, 3483.75],     ["vip seats, dual controls installed", 2214.31, 3481.83],     ["one litter kit installed", 2213.91, 3483.50],     ["one litter, dual controls installed", 2216.11, 3481.58],     ["6 pax standard seats, vests removed", 2196.81, 3489.83],     ["vip seats installed, vest removed", 2203.31, 3487.87],     ["one litter installed, vests removed", 2207.31, 3487.02],     ["two litter installed", 2222.21, 3481.32],     ["two litter, dual controls installed", 2224.41, 3479.41],     ["vip seats, dual controls installed, vests removed", 2205.51, 3485.93],     ["one litter, dual controls installed, vests removed", 2209.51, 3485.09],     ["two litter, dual controls installed, vests removed", 2220.01, 3482.33],     ["floats, raft, vests removed", 2084.51, 3507.26] ];   // set form values selected aircraft option   /////////////////////////////////////////////////////////// function showaircraft(idx) {     var aircraftwb = [aircraft[idx][0]]     alert(aircraftwb);     $("#configwblist").html('');     list(aircraftwb); }  function list(arrary) {     alert(arrary);      // populate selected aircraft w&b select     ///////////////////////////////////////////////////////////     (i = 0; < arrary.length; i++) {         var select = document.getelementbyid("configwblist");         select.options[select.options.length] = new option(arrary[i][0], arrary[i][1]);     }      // reset selected aircraft configuration standard     ///////////////////////////////////////////////////////////     $("#configwblist").val($("#configwblist option:first").val());     $("#configwblist").selectmenu('refresh', true);  }   // initialise form // **************************************************** function initform() {     // populate aircraft select     ///////////////////////////////////////////////////////////     (i = 0; < aircraft.length; i++) {         var select = document.getelementbyid("aircraftlist");         select.options[select.options.length] = new option(aircraft[i][0], aircraft[i][1]);     } }  initform(); 

https://jsfiddle.net/g3h9p2ur/

you can use "eval" result variable data.

<html>  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>  <script language="javascript">  var aircraft = [      ["select aircraft", "", "", "", "", "", "", "", "", ""],      ['n901ah', "agusta a109e", 3000, 1585, 2455, 3200, 5300, 3200, 150, 480],      ['n902ah', "agusta a109e", 3000, 1585, 2455, 3200, 5300, 3200, 150, 480],      ['n903ah', "agusta a109e", 3000, 1585, 2455, 3200, 5300, 3200, 150, 480],      ['n904ah', "agusta a109e", 3000, 1585, 2455, 3200, 5300, 3200, 150, 480],      ['n905ah', "agusta a109e", 3000, 1585, 2455, 3200, 5300, 3200, 150, 480],      ['n907ah', "agusta a109e", 3000, 1585, 2455, 3200, 5300, 3200, 150, 480]  ];    // values ac n901ah  ///////////////////////////////////////////////////////////   var n901ah = [      ["select configuration1", "select config", "select config"],      ["6 pax standard seats offshore", 2205.61, 3485.69],      ["dual controls installed", 2207.81, 3483.76],      ["vip seats installed", 2212.11, 3483.75],      ["vip seats, dual controls installed", 2214.31, 3481.83],      ["one litter kit installed", 2213.91, 3483.50],      ["one litter, dual controls installed", 2216.11, 3481.58],      ["6 pax standard seats, vests removed", 2196.81, 3489.83],      ["vip seats installed, vest removed", 2203.31, 3487.87],      ["one litter installed, vests removed", 2207.31, 3487.02],      ["two litter installed", 2222.21, 3481.32],      ["two litter, dual controls installed", 2224.41, 3479.41],      ["vip seats, dual controls installed, vests removed", 2205.51, 3485.93],      ["one litter, dual controls installed, vests removed", 2209.51, 3485.09],      ["two litter, dual controls installed, vests removed", 2220.01, 3482.33],      ["floats, raft, vests removed", 2084.51, 3507.26]  ];    // values ac n902ah  ///////////////////////////////////////////////////////////   var n902ah = [      ["select configuration2", "select config", "select config"],      ["6 pax standard seats offshore", 2205.61, 3485.69],      ["dual controls installed", 2207.81, 3483.76],      ["vip seats installed", 2212.11, 3483.75],      ["vip seats, dual controls installed", 2214.31, 3481.83],      ["one litter kit installed", 2213.91, 3483.50],      ["one litter, dual controls installed", 2216.11, 3481.58],      ["6 pax standard seats, vests removed", 2196.81, 3489.83],      ["vip seats installed, vest removed", 2203.31, 3487.87],      ["one litter installed, vests removed", 2207.31, 3487.02],      ["two litter installed", 2222.21, 3481.32],      ["two litter, dual controls installed", 2224.41, 3479.41],      ["vip seats, dual controls installed, vests removed", 2205.51, 3485.93],      ["one litter, dual controls installed, vests removed", 2209.51, 3485.09],      ["two litter, dual controls installed, vests removed", 2220.01, 3482.33],      ["floats, raft, vests removed", 2084.51, 3507.26]  ];    // values ac n903ah  ///////////////////////////////////////////////////////////   var n903ah = [      ["select configuration3", "select config", "select config"],      ["6 pax standard seats offshore", 2205.61, 3485.69],      ["dual controls installed", 2207.81, 3483.76],      ["vip seats installed", 2212.11, 3483.75],      ["vip seats, dual controls installed", 2214.31, 3481.83],      ["one litter kit installed", 2213.91, 3483.50],      ["one litter, dual controls installed", 2216.11, 3481.58],      ["6 pax standard seats, vests removed", 2196.81, 3489.83],      ["vip seats installed, vest removed", 2203.31, 3487.87],      ["one litter installed, vests removed", 2207.31, 3487.02],      ["two litter installed", 2222.21, 3481.32],      ["two litter, dual controls installed", 2224.41, 3479.41],      ["vip seats, dual controls installed, vests removed", 2205.51, 3485.93],      ["one litter, dual controls installed, vests removed", 2209.51, 3485.09],      ["two litter, dual controls installed, vests removed", 2220.01, 3482.33],      ["floats, raft, vests removed", 2084.51, 3507.26]  ];    // values ac n904ah  ///////////////////////////////////////////////////////////   var n904ah = [      ["select configuration", "select config", "select config"],      ["6 pax standard seats offshore", 2205.61, 3485.69],      ["dual controls installed", 2207.81, 3483.76],      ["vip seats installed", 2212.11, 3483.75],      ["vip seats, dual controls installed", 2214.31, 3481.83],      ["one litter kit installed", 2213.91, 3483.50],      ["one litter, dual controls installed", 2216.11, 3481.58],      ["6 pax standard seats, vests removed", 2196.81, 3489.83],      ["vip seats installed, vest removed", 2203.31, 3487.87],      ["one litter installed, vests removed", 2207.31, 3487.02],      ["two litter installed", 2222.21, 3481.32],      ["two litter, dual controls installed", 2224.41, 3479.41],      ["vip seats, dual controls installed, vests removed", 2205.51, 3485.93],      ["one litter, dual controls installed, vests removed", 2209.51, 3485.09],      ["two litter, dual controls installed, vests removed", 2220.01, 3482.33],      ["floats, raft, vests removed", 2084.51, 3507.26]  ];    // values ac n905ah  ///////////////////////////////////////////////////////////   var n905ah = [      ["select configuration", "select config", "select config"],      ["6 pax standard seats offshore", 2205.61, 3485.69],      ["dual controls installed", 2207.81, 3483.76],      ["vip seats installed", 2212.11, 3483.75],      ["vip seats, dual controls installed", 2214.31, 3481.83],      ["one litter kit installed", 2213.91, 3483.50],      ["one litter, dual controls installed", 2216.11, 3481.58],      ["6 pax standard seats, vests removed", 2196.81, 3489.83],      ["vip seats installed, vest removed", 2203.31, 3487.87],      ["one litter installed, vests removed", 2207.31, 3487.02],      ["two litter installed", 2222.21, 3481.32],      ["two litter, dual controls installed", 2224.41, 3479.41],      ["vip seats, dual controls installed, vests removed", 2205.51, 3485.93],      ["one litter, dual controls installed, vests removed", 2209.51, 3485.09],      ["two litter, dual controls installed, vests removed", 2220.01, 3482.33],      ["floats, raft, vests removed", 2084.51, 3507.26]  ];    // values ac n907ah  ///////////////////////////////////////////////////////////   var n907ah = [      ["select configuration", "select config", "select config"],      ["6 pax standard seats offshore", 2205.61, 3485.69],      ["dual controls installed", 2207.81, 3483.76],      ["vip seats installed", 2212.11, 3483.75],      ["vip seats, dual controls installed", 2214.31, 3481.83],      ["one litter kit installed", 2213.91, 3483.50],      ["one litter, dual controls installed", 2216.11, 3481.58],      ["6 pax standard seats, vests removed", 2196.81, 3489.83],      ["vip seats installed, vest removed", 2203.31, 3487.87],      ["one litter installed, vests removed", 2207.31, 3487.02],      ["two litter installed", 2222.21, 3481.32],      ["two litter, dual controls installed", 2224.41, 3479.41],      ["vip seats, dual controls installed, vests removed", 2205.51, 3485.93],      ["one litter, dual controls installed, vests removed", 2209.51, 3485.09],      ["two litter, dual controls installed, vests removed", 2220.01, 3482.33],      ["floats, raft, vests removed", 2084.51, 3507.26]  ];  //alert(eval('n901ah'));  var sublistvalue="";  $( document ).ready(function() {  //alert(aircraft.length);       for(i=0;i<aircraft.length;i++)     {  	  	 $('#list1')           .append($("<option></option>")           .attr("value",aircraft[i][0])           .text(aircraft[i][0]));  		   		     }               $('#list1').on('change', function() {     $('#list2').empty();    sublistvalue=eval(this.value ); // or $(this).val()    for(i=0;i<sublistvalue.length;i++)     {  	  	 $('#list2')           .append($("<option></option>")           .attr("value",sublistvalue[i][0])           .text(sublistvalue[i][0]));  		   		     }  });  });  </script>  <select id="list1">  </select>  <select id="list2">  </select>  </html>


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -