473,791 Members | 3,277 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Posting Multiple Listbox Items?

9 New Member
Hi Guys! I have 2 list boxes and the two of them can pass item(s) to each other by highlighting the item(s) and clicking on the -> or <- button, i want to Post the second listbox information to store it on a DB, heres the code:

Expand|Select|Wrap|Line Numbers
  1. <table border="0">
  2.     <tr>
  3.         <td>
  4.             <select class="manuals" name="sel1" id="mylist" size="13" multiple="multiple">
  5.             <?php 
  6.                 $database->getAllTreeNodes(); //Populates the Options List
  7.             ?>
  8.             </select>
  9.         </td>
  10.         <td align="center" valign="middle">
  11.             <input class="botones" type="button" value="--&gt;"
  12.              onclick="moveOptions(this.form.sel1, this.form.sel2);" /><br />
  13.             <input class="botones" type="button" value="&lt;--"
  14.              onclick="moveOptions(this.form.sel2, this.form.sel1);sortlist();" />
  15.         </td>
  16.         <td>
  17.             <select class="manuals" name="sel2" size="13" multiple="multiple"> //This is the one i want to GET with $_POST but if i change the name to "sel2[]" the javascript wont work :S
  18.             </select>
  19.         </td>
  20.     </tr>
  21. </table>
  22.  
how can i post the "sel2" list array?
Thanx For you time =)
Nov 9 '07 #1
7 3649
Atli
5,058 Recognized Expert Expert
Hi.

If you are new to this sort of thing, check out this article.

In your case, you could simply put the entire thing inside <form> tags with the 'method' property set to the .php file you want processing the data, and the 'method' property set to "POST".

Then, in your .php file, simply do something like:
Expand|Select|Wrap|Line Numbers
  1. echo "<pre><b>My Variables</b>:\n";
  2. print_r($_POST['sel2']);
  3. echo "</pre>";
  4.  
Nov 9 '07 #2
sosamv
9 New Member
Thanx! I already did that and im able to get 1 value out of the array, how can i get the others?? with a foreach?
Nov 9 '07 #3
Atli
5,058 Recognized Expert Expert
Ahh I see the problem now.

In order to get multiple values from a <select> box it needs to have a [] at the end of the name.

Consider changing your code, so the Javascript uses the id of the <select> box rather than it's name. Then you are free to change the name so your PHP code can read all the values.

You would have to change:
Expand|Select|Wrap|Line Numbers
  1. <select class="manuals" name="sel2" size="13" multiple="multiple">
  2.  
To:
Expand|Select|Wrap|Line Numbers
  1. <select class="manuals" name="sel2[]" id="sel2" size="13" multiple="multiple">
  2.  
And the Javascript in the onClick events: (Both of them, but remember to keep the forms in their original order)
Expand|Select|Wrap|Line Numbers
  1. // Change this
  2. moveOptions(this.form.sel1, this.form.sel2);
  3.  
  4. // Into this:
  5. moveOptions(this.form.sel1, document.getElementByID('sel2'));
  6.  
I think that should do it.
Nov 9 '07 #4
sosamv
9 New Member
Ahh I see the problem now.

In order to get multiple values from a <select> box it needs to have a [] at the end of the name.

Consider changing your code, so the Javascript uses the id of the <select> box rather than it's name. Then you are free to change the name so your PHP code can read all the values.

You would have to change:
Expand|Select|Wrap|Line Numbers
  1. <select class="manuals" name="sel2" size="13" multiple="multiple">
  2.  
To:
Expand|Select|Wrap|Line Numbers
  1. <select class="manuals" name="sel2[]" id="sel2" size="13" multiple="multiple">
  2.  
And the Javascript in the onClick events: (Both of them, but remember to keep the forms in their original order)
Expand|Select|Wrap|Line Numbers
  1. // Change this
  2. moveOptions(this.form.sel1, this.form.sel2);
  3.  
  4. // Into this:
  5. moveOptions(this.form.sel1, document.getElementByID('sel2'));
  6.  
I think that should do it.

Its is working now!!!, Thank u very much Atli!
=)
Nov 9 '07 #5
Atli
5,058 Recognized Expert Expert
Its is working now!!!, Thank u very much Atli!
=)
Glad I could help :)
Nov 9 '07 #6
loknath11
2 New Member
Please put full your code into fourm. Thank you.
Jun 21 '10 #7
Atli
5,058 Recognized Expert Expert
@loknath11
Hey loknath.
Welcome to Bytes!

This thread was started, and the problem solved, almost three years ago. And there was never any need to post the full code here.

If you have a question, or need help with a problem, please post it into a new thread. But if you are just looking for code to copy into your project, you are in the wrong place.

- Atli
Moderator
Jun 22 '10 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3562
by: theoryboy | last post by:
I'm trying to implement multiple selection functionality in a Tix Hlist using a control-click. I've bound control-click to a function that uses selection_set to add to the selection, but it doesn't seem to work. Only the last clicked item appears selected (highlighted) in the display and the return from info_selection only ever contains the last 2 items, rather than all the items I have control-clicked. It's odd, because if I set up the...
3
22564
by: ted | last post by:
Hi, I can't figure out how to set multiple items in a ListBox to selected when the listbox is in a User Control. When the ListBox is set in directly into a form I can use the following: listbox.SelectionMode = SelectionMode.MultiExtended; listbox.SelectedIndex = 1; listbox.SelectedIndex = 2;
0
2052
by: bill yeager | last post by:
Duray, it helps in regards to knowing how to get the items that were selected in the lisbox, but I'm going in reverse --- after I get the items from the db that were selected, I'd like to be able to highlight them in the listbox within the datagrid control......... Thanks, Bill... >-----Original Message-----
2
2276
by: Peter | last post by:
Hello! Please, could anyone tell, is it possible to set multiple items to be selected in list control in the code? For example when the web form is loaded three items of 5 are selected in list control already? Now I manage to set only one item to be selected during page load, but there is need to multiple items could be selected for the user. I appreciate very much your help! Thanks.
5
3531
by: Lie | last post by:
Hi all, I have problem in getting selectedindex of multiple listbox selection in a datagrid. I have a listbox with multiple selection mode inside datagrid. In Edit mode, I need to get back all selected items of that listbox and display it. can anyone help? Thanks
1
2249
by: sab | last post by:
Hi, We have a web form with a listbox. The listbox is a multiple select listbox and has data that looks something like: ALL Unit 1 Unit 2 Unit 3 Note: "ALL" is always the first item in the list.
3
7396
by: Dany P. Wu | last post by:
Hi everyone, One of my Windows forms contain two listbox controls, with Add and Remove buttons between them. The idea is to allow users to select multiple items from one ListBox, click the Add button, and the selected items will move to the second ListBox. I've been trying to use the ListBox.SelectedObjectCollection with no success. It sounds like the logical thing to use but I can't seem to find
10
6392
by: ads | last post by:
hi, after binding the dropdownlist to a datasource, ive experience this error "Cannot have multiple items selected in a dropdownlist" after using the code: dropdownlist.items.findbyvalue("value").selected = true I didnt specify any selected item in the dropdownlist during binding to the datasource. I use dropdownlist.clearselection() but still error occurs. I need information on this. Thanks. Ads
10
3691
by: kimiraikkonen | last post by:
Hi, I have an app which has a listbox and when i double click an associated fileS, i want their paths to be added into listbox in my application. This code works good when i try to open a "single" file with my app which works to get commandline arguments to get file paths: Dim cla As String() = Environment.GetCommandLineArgs() If cla.Length 1 Then
2
6951
by: 6afraidbecause789 | last post by:
Hi - Has anyone ever used toggle buttons to select items in a listbox? I'd like to put about 24 toggle buttons on an unbound form that select or deselect items in a multiple select listbox. I've come across a way to set the listbox value to only 1 at a time, but need multiple toggle buttons to be on their corresponding listbox item values to be selected. Thanks!
0
9669
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10428
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10207
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10156
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9997
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9030
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5435
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.