Welcome Guest, Not a member yet? Register   Sign In
Option group select
#6

[eluser]Dennis Rasmussen[/eluser]
Oh wait I made a mistake.
Here's the correct code:

Code:
<select name="region">
    <option value="-">-</option>
    &lt;?php
    $currCountry = "";
    foreach($regions as $item) :
        if ($item['country'] != $currCountry)
        {
            if ($endLabel)
            {
                // echo ending label here
                echo '</optgroup>';
            }
            // echo label...
            echo '<optgroup label="' . $item['country'] . '">';
            $currCountry = $item['country'];
            $endLabel = true;
        }
    ?&gt;
    <option value="&lt;?php echo $item['id']?&gt;" &lt;?php if($this->input->get_post('region') == $item['id']) echo 'selected' ?&gt;>&lt;?php echo $item['name']?&gt;</option>
    &lt;?php
    if ($endLabel)
    {
        // echo ending label here
        echo '</optgroup>';
    }
    endforeach;
    ?&gt;
</select>


Messages In This Thread
Option group select - by El Forum - 09-28-2010, 04:51 AM
Option group select - by El Forum - 09-28-2010, 04:59 AM
Option group select - by El Forum - 09-28-2010, 07:22 AM
Option group select - by El Forum - 09-28-2010, 09:30 AM
Option group select - by El Forum - 09-28-2010, 10:58 PM
Option group select - by El Forum - 09-28-2010, 11:01 PM
Option group select - by El Forum - 09-29-2010, 02:18 AM
Option group select - by El Forum - 09-29-2010, 02:21 AM
Option group select - by El Forum - 09-29-2010, 02:43 AM



Theme © iAndrew 2016 - Forum software by © MyBB