Results 1 to 7 of 7

Thread: Simple question about drop-down boxes

  1. #1

    Thread Starter
    Fanatic Member Kzin's Avatar
    Join Date
    Dec 2000
    Posts
    611

    Question Simple question about drop-down boxes

    If I want to have an option in a drop down box that selects more than one value (equivalent to multiselecting what do I do?

    So if the code is currently


    PHP Code:

    <form action="<?php echo $PHP_SELF ?>" method="post">

    <select multiple size=5 name="multiselect[]">
    <option value="one">1</option>
    <option value="two">2</option>
    <option value="three">3</option>
    <option value="four">4</option>
    <option value="five">5</option>

    </select>
    And I want an option that selects 4 and 5 at the same time

    PHP Code:

    <form action="<?php echo $PHP_SELF ?>" method="post">

    <select multiple size=5 name="multiselect[]">
    <option value="one">1</option>
    <option value="two">2</option>
    <option value="three">3</option>
    <option value="four">4</option>
    <option value="five">5</option>
    <option value="four and five">4&5</option>
    </select>
    Does not give the desired result. What should the syntax be?

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    Well, I don't think you can have multi select in a drop down.... but you can in a listbox.

    Ans as for selecting an option...
    Code:
    <option value="four" selected>4</option>
    <option value="five" selected>5</option>
    But that's only going to work once the list box is created (ie, it isn't going to work on the drop down).

    Tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Fanatic Member Kzin's Avatar
    Join Date
    Dec 2000
    Posts
    611
    Originally posted by techgnome
    Well, I don't think you can have multi select in a drop down.... but you can in a listbox.

    Ans as for selecting an option...
    Code:
    <option value="four" selected>4</option>
    <option value="five" selected>5</option>
    But that's only going to work once the list box is created (ie, it isn't going to work on the drop down).

    Tg
    Thanks - but that doesn't do what I need

    I didn't want to make the example too complicated but what I need is the ability to do this (which can't be done by pre-selecting)

    PHP Code:
    <form action="<?php echo $PHP_SELF ?>" method="post"> 

    <select multiple size=5 name="multiselect[]"> 
    <option value="one">1</option> 
    <option value="two">2</option> 
    <option value="three">3</option> 
    <option value="four">4</option> 
    <option value="five">5</option> 
    <option value="three and five">3&5</option> 
    <option value="four and five">4&5</option> 
    </select>

  4. #4
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629
    so.. uhh, do you want to list out all of the possible combinations? or do you want to have multiple selections? or.. what? your description is very vague to me.

    in a select drop down menu you cannot have multiple selections. you can use a listbox for that, though. to select something on load, do what techgnome told you.
    Like Archer? Check out some Sterling Archer quotes.

  5. #5
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Re: Simple question about drop-down boxes

    Originally posted by Kzin
    Does not give the desired result. What should the syntax be?
    What is the desired result?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  6. #6

    Thread Starter
    Fanatic Member Kzin's Avatar
    Join Date
    Dec 2000
    Posts
    611
    Well the desired result is to have a single option that *acts* like a particular multiselection of options and another single option that acts like a different multiselection.

    Like this (see last two options)

    PHP Code:
     <form action="<?php echo $PHP_SELF ?>" method="post"> 

    <select multiple size=5 name="multiselect[]"> 
    <option value="1">BBC Micro</option> 
    <option value="2">Apple II</option> 
    <option value="3">IBM AT</option> 
    <option value="4">Archimedes RISC5000</option> 
    <option value="5">VAX-11</option> 
    <option value="1&4">British Computers</option> 
    <option value="4&5">32-Bit Computers</option> 
    </select>

  7. #7
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by Kzin
    Well the desired result is to have a single option that *acts* like a particular multiselection of options and another single option that acts like a different multiselection.

    Like this (see last two options)

    PHP Code:
     <form action="<?php echo $PHP_SELF ?>" method="post"> 

    <select multiple size=5 name="multiselect[]"> 
    <option value="1">BBC Micro</option> 
    <option value="2">Apple II</option> 
    <option value="3">IBM AT</option> 
    <option value="4">Archimedes RISC5000</option> 
    <option value="5">VAX-11</option> 
    <option value="1&4">British Computers</option> 
    <option value="4&5">32-Bit Computers</option> 
    </select>
    And why isn't it working for you? Your PHP variable would be $_POST['multiselect'][$i] = '4&5', which is exactly how you're coding it to be.

    Do you want the results seperate, so you'll have $_POST['multiselect'][$i] = 4 and $_POST['multiselect'][$i] = 5?

    If so, there's nothing you can drop in that form that will give you that. There's no way to do it, unless you write some javascript that reconstructs the array before submission, or write some PHP code that reconstructs the array after submission.
    My evil laugh has a squeak in it.

    kristopherwilson.com

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