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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

multiple select form question

  • 10-09-2005 8:36am
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 Posts: 5,333 ✭✭✭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, Registered Users 2 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