I am using jQuery.chained so that when you select a Country from a drop down it filters a Province/State dropdown. However it requires that each <option> have a class name with the corresponding country.
This is what I have so far
$options = array(
//Canada
"AB" => "Alberta",
"BC" => "British Columbia",
"MB" => "Manitoba",
//etc...
//United States
"AL" => "Alabama",
"AK" => "Alaska",
"AZ" => "Arizona",
//etc...
);
echo form_dropdown('province', $options, $province);
This gives me
<option value="AB" selected="selected">Alberta</option>
<option value="BC">British Columbia</option>
<option value="MB">Manitoba</option>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
But what I need is
<option value="AB" class="canada" selected="selected">Alberta</option>
<option value="BC" class="canada">British Columbia</option>
<option value="MB" class="canada">Manitoba</option>
<option value="AL" class="us">Alabama</option>
<option value="AK" class="us">Alaska</option>
<option value="AZ" class="us">Arizona</option>
So how would I go about adding a class to each <option>. I would assume I probably need a custom helper but I have no idea how to go about creating one. I am new to coding. Can anyone help me? Thanks.
You can extend the default form_helper, create a custom helper, or add the classes via JavaScript.
CodeIgniter has been created so you can over-ride the existing code very easily
To create a custom helper
You would load/use the new helper the exact same way you used the old one.
The other option is add the classes via JavaScript before calling the jQuery plugin depending on your level of code skill you might find this option easier.
CodeIgniter’s user guide is a very useful source of information
Hope that helps if you have a hard time writing the actual function post what you already tried and I can probably help you with it, The other option would be grab the helper off another CodeIgniter based application or maybe look for a Spark. I know CI-Bonfire has a very useful Address helper and I’m pretty sure I saw a Spark for it also.