www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] how to get the value of multiple dropdown?

  1. #1
    Join Date
    Mar 2006
    Posts
    48

    resolved [RESOLVED] how to get the value of multiple dropdown?

    i got this code @ file.php
    PHP Code:
        // Dropdown: Chemicals
        
    $chemicalsDropdown getDropdown("CHEMICALS");
        while (list(
    $key$value) = each($chemicalsDropdown)) {
                if (
    $key == $_SESSION['enquiryPage']['wheel']['environment_chemicals']){
                
    $is_selected "selected"
                } 
            else { 
    $is_selected ""
                }
            
    $template->process('CHEMICALS_LIST', array(
                
    'list_id'       => $key,
                
    'list_value'    => $value,
                
    'list_selected' => $is_selected
            
    )); 
    and this code @ file.tpl
    PHP Code:
            <select name="environment_chemicals" multiple size="5" style="width: 300px;">
              <
    option value="0">[NO_CHEMICALS]</option>
              {
    section CHEMICALS_LIST}
              <
    option value="{list_id}" {list_selected}>{list_value}</option>
              {/
    section CHEMICALS_LIST}
            </
    select
    i can select more than 1 chemical,
    but after i press save button, the result will show only the last id that selected
    how to get the other selected chemicals?
    thx
    Last edited by cmon1011; 04-21-2006 at 04:09 AM. Reason: how to get the value of multiple select?

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,935
    Make the name of the SELECT element end in "[]", e.g.:
    Code:
    <select name='example[]'>
    This will then populate an array of selected values in your $_POST array. For example, if you selected 3 items, then $_POST['example'][0] would contain the first, $_POST['example'][1] the second value, and $_POST['example'][2] the last value.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Mar 2006
    Posts
    48
    thx
    it's working now

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles