Tag Archives: Multiple Selection

Multiple Selection

By default, PHP Autocomplete allows selection of a single value. To select multiple values, call enable_multiple() method and pass true.

<?php
$data =
    array(
        array('id'=>1, 'text'=>'Japan'),
        array('id'=>2, 'text'=>'USA'),
        array('id'=>3, 'text'=>'Hong Kong'),
        array('id'=>4, 'text'=>'Canada'),
        array('id'=>5, 'text'=>'Brazil')
    );
$pac = new C_PhpAutocomplete('country', $data);
$pac -> enable_multiple(true);    
$pac -> display();
?>
<input type="hidden" id="country">

Note that When attached to a <select> element this value will be ignored and <select> multiple attribute will be used instead.

<?php
$pac = new C_PhpAutocomplete('country');
$pac -> enable_multiple(true);    // will be ignored
$pac -> display('SELECT');
?>
<select id="country" multiple>
    <option id="1">Japan</option>
    <option id="2">USA</option>
    <option id="3">Hong Kong</option>
    <option id="4">Canada</option>
    <option id="5">Brazil</option>
</select>