JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

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:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old March 21st, 2004, 06:01 PM
anicols anicols is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 2 anicols User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
referencing a multiple select box with an array name

Hi,

I've been trying to get a piece of Javascript and it's doing my head in.

The code moves elements from one multiple select box to another (you'll see what I mean) This all works fine at the moment for the Javascript side of things,but I need to be able to read all of the values being submitted for my PHP query.

To do that, I need to have a multiple select box called chosen[] instead of chosen from what I can tell but I'm not too handy with Javascript.

I've tried simply replacing chosen with chosen[] in all instances, but not to much success, I get errors. Please could someone give me some advice on how to do this as I've been at it for several hours and can't do it.

Thanks

Code:


<script LANGUAGE="JavaScript">
<!--
function copyToList(from,to){
fromList = eval('document.forms[0].' + from);
toList = eval('document.forms[0].' + to);
if(toList.options.length >0&& toList.options[0].value == 'temp'){
toList.options.length =0;
}var sel =false;
for(i=0;i<fromList.options.length;i++){var current = fromList.options[i];
if(current.selected){
sel =true;
if(current.value == 'temp'){
alert ('You cannot move this text!');
return;
}
txt = current.text;
val = current.value;
toList.options[toList.length]=new Option(txt,val);
fromList.options[i]=null;
i--;
}}if(!sel) alert ('error');
}function allSelect() {
List = document.forms[0].chosen.selectedIndex;
if(List.length && List.options[0].value == 'temp')return;
for(i=0;i<List.length;i++) {
List.options[i].selected =true;
}}
// -->
</SCRIPT>

<form onSubmit="allSelect(); return" method="post">
<p>From:<br>
<select NAME="possible" SIZE="8" MULTIPLE>
<option value="1">One</option>
<option value="2">Two</option>
</select>

<aHREF="javascript:copyToList('possible','chosen')">Add to Booking</a><br>
<aHREF="javascript:copyToList('chosen','possible')">Remove from Booking</a>
<p>To:<br>
<select NAME="chosen" SIZE="8" MULTIPLE>
<option VALUE="temp">Make your choice on the left
</select>
<input TYPE=submit>

</form>

Reply With Quote
  #2  
Old March 21st, 2004, 07:30 PM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 6 m 11 sec
Reputation Power: 8
Send a message via ICQ to stumpy Send a message via MSN to stumpy
So if i understand correctly, you have 2 list boxes. One is used to pass options across to the other (which is empty to start with?)

If so, you just need to modify your allSelect() function so that it adds each option found in the choosen select object, to a CSV'd string (strList.value += option value). Once that's done, place the value of the string in a hidden form field, that gets submitted with the form.
__________________
DevArticles Moderator
BlueSix - Web Development and Consulting

Reply With Quote
  #3  
Old March 22nd, 2004, 11:33 PM
cgnovelo cgnovelo is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 14 cgnovelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Maybe you're not getting the values you want because the values in a "select" list only get sent when they are selected. So unless you try the approach suggested above, you would need to use another javascript function which would select all elements in the "chosen" list before the submit. This would give you a string in the same form: 1, 2, etc., that you would need to split before using when receiving in PHP.

Reply With Quote
  #4  
Old March 23rd, 2004, 04:07 AM
anicols anicols is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 2 anicols User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Just tried Stumpy's idea and works spot on.

The allSelect() function selects all of the elements in the listbox anyway.

Thanks guys,

Andrew

Reply With Quote
  #5  
Old March 23rd, 2004, 06:19 PM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 6 m 11 sec
Reputation Power: 8
Send a message via ICQ to stumpy Send a message via MSN to stumpy
My solution will also work if you do not have the list box set to "multiple".

Reply With Quote
  #6  
Old May 31st, 2004, 07:08 AM
Paul Taylor Paul Taylor is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 1 Paul Taylor User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Andrew,

Would it be possible for you to post the solutions code here, as I'm also doing this and I am having no luck.

Thanks

Paul

Reply With Quote
  #7  
Old July 12th, 2004, 07:24 AM
callidus callidus is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 1 callidus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
U also used your javascript, thanks!

It works if you replace one of your lines in allSelect() by this one


List = document.forms[0].chose;





Quote:
Originally Posted by anicols
Just tried Stumpy's idea and works spot on.

The allSelect() function selects all of the elements in the listbox anyway.

Thanks guys,

Andrew

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > referencing a multiple select box with an array name


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 3 hosted by Hostway