In the following script, the 'choices' array is defined correctly.
It also displays as expected with the showArray() function.
I was experimenting to see if I could dynamically create a similiar array of array (picks),
but I'm having difficulty with my syntax.
I highlighted the commands I believe are not correct in RED.
Does anyone have an idea how I can duplicate the 'choices' array into the 'pick' array.
Code:<html> <body> <form id="drop_list" onsubmit="return false"> <button onclick="showArray(choices)">Choice display</button> <button onclick="showPicks()">Picks display</button> </form> <script type="text/javascript"> var choices = [ // an array OF arrays */ [ "AK", "Alaska" ], [ "AL", "Alabama" ], [ "AR", "Arkansas" ], [ "AZ", "Arizona" ], [ "CA", "California" ], [ "FL", "Florida" ], [ "GA", "Georgia" ], [ "TX", "Texas" ], [ "VT", "Vermont" ] // Note: No comma after last entry ]; // want to create above array of arrays from strings below var picks = []; var arrStates = [ "AK:Alaska", "AL:Alabama", "AR:Arkansas", "AZ:Arizona", "CA:California", "FL:Florida", "GA:Georgia", "TX:Texas", "VT:Vermont" ]; // following is NOT used at this time. // var strStates = "AK:Alaska|AL:Alabama|AR:Arkansas|AZ:Arizona|CA:California|FL:Florida|GA:Georgia|TX:Texas|VT:Vermont"; function showPicks() { var tarr = []; for (var i=0; i<arrStates.length; i++) { tarr = arrStates[i].split(':'); picks.push([tarr[0]],[tarr[1]]); // this does not appear to work as desired // picks.push([tarr[0]]+','+[tarr[1]]); // neither does this } showArray(picks); } function showArray(arr) { var abb = sta = ''; for (var i=0; i<arr.length; i++) { abb += arr[i][0]+'\n'; } for (var i=0; i<arr.length; i++) { sta += arr[i][1]+'\n'; } alert(arr.join('\n')+'\n\n'+abb+'\n\n'+sta); } </script> </body> </html>


Reply With Quote
Bookmarks