SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Wizard jumpthru's Avatar
    Join Date
    Apr 2000
    Location
    Los Angeles, California
    Posts
    1,008
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have a form and in the form there is a select box. You know a box where you can click multiple items in the list. After you send the form how do you access which ones were clicked or not. You cant just do the normal

    if ($nameoflist = "valueoflist")

    because there are multiple values for the same name...anyone know what i am talking about?

  2. #2
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    um. Radio buttons should all have the same name.

    Checkboxes should not.

    Then if a box is checked will return a "yes" or "1" value. If it is not checked it will return no value.


  3. #3
    SitePoint Zealot
    Join Date
    Jun 2000
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How's it going?

    The value in the select name in your form is the variable passed to the next page.

    So if you type:

    echo "$optionselected"; - this'll give you the value of the option selected.

    Be sure to give values to your options in the form.

    E.g.

    <form name="form1" >
    <select name="optionselected">
    <option value="value1">name1</option>
    <option value="value2">name2</option>
    </select>
    </form>

    Then if the user selects name2, when you test this variable on the receiving page the value will be equal to "value2" so you know what the user selected.

    Cheers,

    Jason

  4. #4
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Jumpthru,

    I believe you're asking about how to get the selected items in a <SELECT MULTIPLE> tag, right?

    If so, your question is answered in the PHP FAQ at the following address:

    http://www.php.net/FAQ.php#7.14
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    jumpthru, Your select list should have a name like:

    <select name="selectbox[]" multiple>
    <option value="1">1
    <option value="2">2
    <option value="3">3
    <option value="4">4
    <option value="5">5
    </select>

    After you send the form you will have an array named $selectbox that contains the values which were clicked.
    So if user clicked 2, 4 and 5

    $selectbox would be an array containing ("2", "4", "5");

    BTW when testing for a variable you need two == signs so your example above would be
    if ($nameoflist == "valueoflist")
    Of course this wouldn't work for the selectbox. Because its an array
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  6. #6
    SitePoint Wizard jumpthru's Avatar
    Join Date
    Apr 2000
    Location
    Los Angeles, California
    Posts
    1,008
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay thanks, that was what i was talking about the <SELECT MULTIPLE> tag.

  7. #7
    SitePoint Member
    Join Date
    Jan 2001
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just wanted to post a thank you to all that posted in this thread. i'm just learning php (switching from perl/cgi) and i've been banging my head constantly wondering why this thing wasn't working. i've ingested so much mountain dew over the past few days that i could have sworn that at one point it worked.

    anyway, thanks for the info on the arrays.

    also, there is a similar post for anyone viewing this site that was in the same situation as me: http://www.sitepointforums.com/showt...threadid=12951

    and while i'm at it ... here's how i used the code in my php program:

    $extras is a -select multiple- in a form that is passed to this php.


    $newextras="";
    /// put the array -extras- into a linear variable
    for ($i=0;$i<count($extras);$i++) {
    $newextras .= sprintf(" %s,", $extras[$i]);
    }
    $extras = $newextras;



    i handle it this way so i can save all the selections into one field in the table. then when the user is searching that field for their multiple selections ... i use the eregi() function to locate.


    if (eregi("$extras","$value"))


    once again ... thanks for the help ...


    <Edited by timcaviness on 01-24-2001 at 11:19 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
  •