|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
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 ![]() |
|
#3
|
|||
|
|||
|
cheers mitch!!
It works perfectly now!!! Thanks V MUCH!! ![]() |
|
#4
|
|||
|
|||
|
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, |
|
#5
|
|||
|
|||
|
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, |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Programming Tools > Javascript - Arrays + select box... |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|