Connecting Tech Pros Worldwide Help | Site Map

populating select menus from multidimensional arrays and returning values on go

  #1  
Old August 28th, 2008, 01:42 PM
Newbie
 
Join Date: Aug 2008
Posts: 3
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!
  #2  
Old August 28th, 2008, 02:07 PM
RamananKalirajan's Avatar
Needs Regular Fix
 
Join Date: Mar 2008
Location: Chennai - India
Posts: 344

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
  #3  
Old August 28th, 2008, 02:18 PM
Newbie
 
Join Date: Aug 2008
Posts: 3

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
  #4  
Old August 29th, 2008, 04:58 AM
RamananKalirajan's Avatar
Needs Regular Fix
 
Join Date: Mar 2008
Location: Chennai - India
Posts: 344

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
  #5  
Old August 30th, 2008, 05:01 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,526
Provided Answers: 12

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"]];
  #6  
Old August 31st, 2008, 10:14 AM
Newbie
 
Join Date: Aug 2008
Posts: 3

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


Thanks, I shall do just that to start off with
  #7  
Old August 31st, 2008, 12:54 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,526
Provided Answers: 12

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