Page 1 of 1

select all options in dropdown menu

Posted: Sat Aug 16, 2003 6:08 pm
by qads
hi,
i was wondering how could i select/de-select all the options in a dropdown box with links, something like phpmyadmin does on Export page, i have searched around but have't found anything yet :?.
thanks in adv

Posted: Sun Aug 17, 2003 6:53 am
by qads
never mind, if someone else needs it then here it is:

Code: Select all

<script type="text/javascript">
function setSelectOptions(the_form, the_select, do_check)
&#123;
    var selectObject = document.forms&#1111;the_form].elements&#1111;the_select];
    var selectCount  = selectObject.length;

    for (var i = 0; i < selectCount; i++) &#123;
        selectObject.options&#1111;i].selected = do_check;
    &#125; // end for

    return true;
&#125;
</script>

<form method="POST" action="main.php" name="items">
<a href="#" onclick="setSelectOptions('items','options', true); return false;">Select All</a> | <a href="#" onclick="setSelectOptions('items','options', false); return false;">Unselect All</a><br />
<select name="options" size="8"  multiple>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">3</option>
<option value="4">Four</option>
</select>
</form>