Connecting Tech Pros Worldwide Help | Site Map
Reply
 
LinkBack Thread Tools Search this Thread
  #1  
Old August 28th, 2008, 01:42 PM
Newbie
 
Join Date: Aug 2008
Posts: 3
Default populating select menus from multidimensional arrays and returning values on go

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!
Reply
  #2  
Old August 28th, 2008, 02:07 PM
RamananKalirajan's Avatar
Familiar Sight
 
Join Date: Mar 2008
Location: Chennai - India
Age: 24
Posts: 243
Default

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

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
Reply
  #4  
Old August 29th, 2008, 04:58 AM
RamananKalirajan's Avatar
Familiar Sight
 
Join Date: Mar 2008
Location: Chennai - India
Age: 24
Posts: 243
Default

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

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

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

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

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,248 network members.