Programming Tools
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingProgramming Tools

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 21st, 2002, 08:27 PM
fakker fakker is offline
The calm b4 the storm
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Manchester, UK
Posts: 404 fakker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via Yahoo to fakker
Javascript - Arrays + select box...

hey,

I need some help with my Javascript.... here's the scenario..

There is a populated "select" list on the left (called "list A")...eg:

List A
------------
<option1>
<option2>
<option3>

There is also a list below which is empty. The user can select an option from the list above, press a button, and add it to another list.... we'll call this "list B". List B looks like:

List B
------------

Cos it is an empty <select> area.... (10 rows in depth)...

Once the user selects something from List A.. eg: <option 3> and presses the "Add From List A to B" button... List B would then look like:


List B
------------
<option3>

So List b is now populated with <option3>...

NOW.... my question is... how to I get the contents of what ever is in LIST B in to my PHP code....

I've tried:

Code:
var listB= window.document.forms[0].listB;
var len = listB.options.length;
var list = new Array(len)
for (i=0; i<list.length; i++)
{	
	list[i] = document.write(listB.options.text[i] + "<br>");

}


The array works ok... so if there are two elements in listB, it has two elements in the array... I'm ust having trouble when getting the actual WORDS out of the list!!

Idealy what I want to happen is the following output:

0 - <option3>
1 - <option2>
2 - <option1>

the above is assuming that the user has entered all three from ListA...

Does any one know of a way to loop through what ever is in ListB and get the actual value????

Cheers.
__________________
Matt 'Fakker' Facer

mattfacer.com

Reply With Quote
  #2  
Old October 21st, 2002, 08:29 PM
mytch mytch is offline
Dev Articles Novice (500 - 999 posts)
 
Join Date: Apr 2002
Location: Sydney, Australia
Posts: 589 mytch User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Hey Matt,
Try this:

var listB= window.document.forms[0].listB;
var len = listB.length;
var list = new Array(len);

for (i=0; i<len; i++)
{
list[i] = listB.options[i].text;
}

Hope that helps you out

Reply With Quote
  #3  
Old October 21st, 2002, 08:40 PM
fakker fakker is offline
The calm b4 the storm
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Manchester, UK
Posts: 404 fakker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via Yahoo to fakker
cheers mitch!!

It works perfectly now!!!


Thanks V MUCH!!


Reply With Quote
  #4  
Old January 12th, 2004, 09:44 AM
DDDooGGG DDDooGGG is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Melbourne, Australia
Posts: 97 DDDooGGG User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 33 sec
Reputation Power: 6
Can you post the javascript function in complete, as im not very good at JS. do i need to add this to th onSubmit or where?

thanks,

Reply With Quote
  #5  
Old January 23rd, 2004, 10:41 AM
t-bird69 t-bird69 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 1 t-bird69 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Reply ---

Try this...

* Edit: Please enclose code within the appropriate code tags. *

Code:
  ArrayLength = document.frm.loca.options.length;
   locaArray = new Array(ArrayLength);

   //Populate the tables
   for(s=0; s<ArrayLength; s++){
	   locaArray[s] = document.frm.loca.options[s].text;
   }

   //Clear the list boxes out

   var y=ArrayLength;
   while (y > -1){
	   document.frm.loca.options[y] = null;
	   --y;
   }
   
   document.frm.loca.options[0] = new Option("--Select---");

   temp = new Array(ArrayLength);
   var ct = 0;
   var cp = 0;
   var xx = 0;
   var cnt = 0;
   var bobby = 0;
   var currentposition = 0;
   var placeholder = 1;
   var temps="";
   var loca2_num_hold = 0;
   
   while(currentposition < ArrayLength){
       if(temps != locaArray[currentposition]){
          document.frm.loca.options[placeholder] = new Option(locaArray[currentposition]);
		  temps = locaArray[currentposition];
		  temp[cnt] = locaArray[currentposition];
		  ++cnt;
          ++placeholder;
       }
	   ++currentposition;
   }


what you need to do is take the length of your first array and hold it... Then based on your selecteIndex pass it to your second drop down making sure you use the "new Option method to populate the second drop down list... Very similiar to dynamic drop down list... Do a search you should be able to find more code

Thanks,

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingProgramming Tools > Javascript - Arrays + select box...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT