0

I have a select control in my php web site i need to show it as a drop down list collapsed and i need to select multiple option, i use the folowing code

echo '<select class="form-control" multiple name="associate" >';
echo "<option value='0' class='form-control' >---Choose Associate---</option>"; 
foreach ($userarray as $key => $value)
{
    if (isset($_REQUEST['associate']))
    {
        echo "<option value='".$key."' class='form-control' >".$value."</option>"; 
    }
    else
    {
        echo "<option value='".$key."' class='form-control' >".$value."</option>";
    }
}
echo '</select>';

The problem is that the drop down look like this in the picture, i need to collapse it not to show it like this .. i dont need to see all the items!! just first one and when i click the others appearsenter image description here

dazed-and-confused
  • 1,293
  • 2
  • 11
  • 19
Malo
  • 1,232
  • 2
  • 17
  • 28

1 Answers1

1

Here's a sample of how you can do this:

<select multiple size="1" onfocus="show_more()" onblur="show_less()" id="my_select">
    <option>1</option>
    <option>2</option>
    <option>3</option>
</select>
<script>
function show_more()
{
    document.getElementById('my_select').size = 3;
}
function show_less()
{
    document.getElementById('my_select').size = 1;
}
</script>

View in jsFiddle https://jsfiddle.net/qodw5xe9/

Note: This can be done using a single function which accepts the size as a parameter. I broke it out to explicitly show what's going on.

dazed-and-confused
  • 1,293
  • 2
  • 11
  • 19