+ Reply to Thread
Results 1 to 4 of 4

Thread: Pass all values in a select multiple field

  1. #1
    Barn Regular bryceowen is on a distinguished road bryceowen's Avatar
    Join Date
    Sep 2008
    Location
    Jacksonville, FL
    Posts
    93
    Rep Power
    4

    Pass all values in a select multiple field

    I don't really know if this should be under PHP, HTML or JavaScript, but here's what I'm trying to do:
    I have a form that has two multiple select boxes that you can pass values between. (See JavaScript Toolbox - Selectbox / Select Box Functions For Manipulating Options, Etc for the script I'm using. It's the second example on that page.) Now, the JS is working just fine, but how do I tell the form to pass all values in list2 to the next page without the user being required to select them all before submitting?

  2. #2
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    After you post the page, you should be able to do something like this:
    PHP Code:
        $value=$_POST['listbox2'];
        if (
    $value){
         foreach (
    $value as $str){echo 'You selected ',$str,'<br />';}
        } 
    edit: scratch that, just realized you're trying to pass all items in the listbox...let me ponder that
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  3. #3
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    Okay, one way to handle this is to autoselect everything using JavaScript when you submit the form:
    Code:
    function selectall(form)
    {
    	var elem = form.elements['listbox2'];
    	
    	for (i = 0; i < elem.length; i++)
    	{
    		elem[i].selected = true;
    	}
    }
    
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  4. #4
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    I think this is more of a JS issue.

    Only items that are selected would be posted back to be retrieved on the server side. So, you have to get the items in the listbox into a retrievable form first.

    I'd think some form of JS function that takes the items in your listbox and populates a hidden field before the form is submitted so the value from the hidden field can be retrieved on the server.

    Unless anyone else has any other ideas..

    <edit>J already posted a solution. I think his way you'd see the elements selected (highlighted) just before the form submits, but it should work</edit>

+ Reply to Thread

Similar Threads

  1. Counting a field of two columns if the values don't match in SSRS
    By kristilee in forum SQL Server Reporting Services Help
    Replies: 5
    Last Post: September 4th, 2009, 12:21 PM
  2. Pass different value thru button?
    By Rebelle in forum ASP Development
    Replies: 2
    Last Post: August 10th, 2009, 11:34 AM
  3. pass more than one parameter in grid view
    By guddu in forum .NET Development
    Replies: 7
    Last Post: March 4th, 2009, 08:30 AM
  4. Select with NULL values
    By Wolffy in forum .NET Development
    Replies: 7
    Last Post: February 13th, 2009, 12:17 PM
  5. when using multiple search values
    By Rebelle in forum Microsoft Access
    Replies: 2
    Last Post: February 6th, 2009, 04:03 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO