Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

multiple select form question

Options
  • 10-09-2005 9:36am
    #1
    Registered Users Posts: 252 ✭✭


    tricky one here, if anyone of you can help ...

    i have a multiple select box in a form populated with values.

    If i select these values then they get passed through as an array.

    However how do i pass through the values without having to select them??

    Tnx


Comments

  • Banned (with Prison Access) Posts: 16,659 ✭✭✭✭dahamsta


    You have to select them, that's how forms work. If it's not done manually you can do it with javascript, bearing in mind the possibility that it might not be available or enabled for some users.


  • Registered Users Posts: 5,335 ✭✭✭Cake Fiend


    You could use hidden form inputs to pass these values. As in:

    [PHP]
    <form action="whatever.php" method=POST>

    What kind of food do you like?<br>

    <select name="choices[]" multiple>
    <option>Cheese</option>
    <option>Haggis</option>
    <option>Spuds</option>
    </select>

    <input type=hidden name="options[]" value="Cheese">
    <input type=hidden name="options[]" value="Haggis">
    <input type=hidden name="options[]" value="Spuds">
    <br>
    <input type=SUBMIT>
    </form>
    [/PHP]

    And 'whatever.php' could contain something like this:

    [PHP]
    <?php

    $options = $_POST;
    $choices = $_POST;

    echo "The choices were:<br><br>";

    foreach($options as $option)
    echo "$option<br>";

    echo "<br>You chose:<br><br>";

    foreach($choices as $chosen)
    echo "$chosen<br>";

    ?>
    [/PHP]


  • Registered Users Posts: 1,268 ✭✭✭hostyle


    [php]
    <option value="stuff" selected="selected">stuff</option>
    <option value="things">things</option>
    <option value="what nots" selected="selected">what nots</option>
    [/php]


Advertisement