Connecting Tech Pros Worldwide Forums | Help | Site Map

populating select menus from multidimensional arrays and returning values on go

Newbie
 
Join Date: Aug 2008
Posts: 3
#1: Aug 28 '08
Hey,
I've been trying to learn javascript for a few days. I'm a bit stuck!

I'd appreciate any links to get me going in the right direction or any advice I can get.

I've written a multidimensional array like this:
Expand|Select|Wrap|Line Numbers
  1. var from_array = new Array();
  2.  
  3. from_array['Adelaide'] =
  4. new Array ( "Alice Springs", "1.5", "2.8"); new Array ( "Amberley", "1.5", "2.8") ;
  5. from_array['Canberra'] = new Array( "Adelaide", "1.5", "2.8" ); new Array ( "Alice Springs", "1.5", 
  6.  
  7. "2.8");
I want to populate a select menu based on this. It should list Adelaide and Canberra. There is also the need for a 2nd select menu which I could write the array in a similiar way or possibly reuse that array.

So the HTML page will have: From <select menu 1> and To <select menu 2>

If a user selects Canberra and Adelaide on Go - I want it to return the value from the above array, which would be 1.5 if they select the first radio button or 2.8 if they select the 2nd radio button.

I'm assuming I need a function written and to call that function - not sure how to write it though.

Would appreciate any advice... I'm more a CSS monkey!

RamananKalirajan's Avatar
Needs Regular Fix
 
Join Date: Mar 2008
Location: Chennai - India
Posts: 349
#2: Aug 28 '08

re: populating select menus from multidimensional arrays and returning values on go


You want a select list box with radio button inside displaying the values what you had specified in the array. is it ur requirement

Regards
Ramanan Kalirajan
Newbie
 
Join Date: Aug 2008
Posts: 3
#3: Aug 28 '08

re: populating select menus from multidimensional arrays and returning values on go


Quote:

Originally Posted by RamananKalirajan

You want a select list box with radio button inside displaying the values what you had specified in the array. is it ur requirement

Regards
Ramanan Kalirajan


No, not quite...

this may illustrate what i'm trying to do based on those values
http://cathyjenkins.com/example.jpg
RamananKalirajan's Avatar
Needs Regular Fix
 
Join Date: Mar 2008
Location: Chennai - India
Posts: 349
#4: Aug 29 '08

re: populating select menus from multidimensional arrays and returning values on go


Quote:

Originally Posted by cathyisfrustrated

No, not quite...

this may illustrate what i'm trying to do based on those values
http://cathyjenkins.com/example.jpg

Why you are storing each and every option value in the array. For each option in the select u are having different values in the radio. Do you want to set the radio values dynamically onselect of an option from the select. Is this ur requirement

Regards
Ramanan Kalirajan
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#5: Aug 30 '08

re: populating select menus from multidimensional arrays and returning values on go


First of all, you need to correct the array setting. Try something like:
Expand|Select|Wrap|Line Numbers
  1. from_array['Adelaide'] =
  2. [["Alice Springs", "1.5", "2.8"],["Amberley", "1.5", "2.8"]];
Newbie
 
Join Date: Aug 2008
Posts: 3
#6: Aug 31 '08

re: populating select menus from multidimensional arrays and returning values on go


Thanks, I shall do just that to start off with
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#7: Aug 31 '08

re: populating select menus from multidimensional arrays and returning values on go


No problem. Post back here if you get stuck with the rest of it.
Reply