Welcome Guest, Not a member yet? Register   Sign In
load second dropdown values based on the first (how to implement AJAX)
#2

[eluser]ELRafael[/eluser]
You didn't call the js function on the first dropdown. Try to put in the drowpdown something like this

Code:
<!-- put onchange below. the ci forum didn't show what i wrote :( -->
<select name="Project_ID" id="Project_ID">
</select>

You can try use JQuery, I think its a little better. An example:

Code:
[removed]
// &lt;![CDATA[

$(document).ready(function() {
    
    $("select[@name=states]").change(function() {
            $("select[@name=city]").html('<option>Searching...</option>');
            $.post(base_url+'search_city', { uf: $(this).val() }, function (retorno) {
                    $("select[@name=city]").html(retorno);
            });
    });
                  
});

// ]]>
[removed]

//The view
<select name="states" id="states">
  <option value="0" selected="selected">Selecione um estado</option>
  &lt;?php foreach($states->result() as $state) : ?&gt;
  <option value="&lt;?php echo $state->id; ?&gt;">&lt;?php echo $state->name; ?&gt;</option>
  &lt;?php endforeach; ?&gt;
</select>

<select name="city" id="city">
</select>

In this case, every time that select with name states changed, will pass by post (you can change to get) to method search_city the var uf. This var have the id value. In the search_city method you return something like this
Code:
echo '<option value="'.$city_id.'">'.$city_name.'</option>';


Messages In This Thread
load second dropdown values based on the first (how to implement AJAX) - by El Forum - 10-21-2008, 05:38 AM



Theme © iAndrew 2016 - Forum software by © MyBB