Results 1 to 2 of 2

Thread: Handling a Multiple Drop Down Box

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Handling a Multiple Drop Down Box

    Hello I have a <select name="dropbox" multiple="multiple" size="2"> in a form. When the user clicks the submit button the method used is POST.

    I then handle the information by storing it in a variable.
    Code:
    $myMultiDropDownBox = $_POST['dropbox'];
    I then tried to echo that variable. When multiple options were selected the echo wouldn't work. How do I handle the various items the user may have selected? Is it stored in an array? Hence I must do a loop?

  2. #2
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: Handling a Multiple Drop Down Box

    For PHP, you'll need to declare the select name as an array...
    Code:
    <select name="dropbox[]" multiple="multiple" size="2">
    <option value="1">Option 1</option>
    <option value="2">Option 2</option>
    </select>
    ...in order to receive an array of the values...
    Code:
    print_r($_POST['dropbox']);
    /* if you selected both options, this prints:
    
    Array
    (
        [0] => 1
        [1] => 2
    )
    
    */
    echo $_POST['dropbox'][0]; //echos 1
    echo $_POST['dropbox'][1]; //echos 2
    Last edited by SambaNeko; Aug 11th, 2009 at 03:00 PM.

Posting Permissions

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



Click Here to Expand Forum to Full Width