Welcome Guest, Not a member yet? Register   Sign In
Get value from selected form_dropdown()
#15

[eluser]bondjp[/eluser]
Yeah. Thanks.

I had to change this a bit so here's what's happening.
I now have 2 dropdown boxes. I click the first and the second shows the info based on the first one.
It's not working right because when i click the first dropdown the second gets populated with the last values in the database.
Here's what i'm saying:

Drop1
Drop2
Drop3

DB:
Id1 Item for Drop1
Id2 Item for Drop1
Id3 Item for Drop2
Id4 Item for Drop2
Id5 Item for Drop3
Id6 Item for Drop3

Whenever i select drop2 or 3 the next dropdown gets populated with Id5 and Id6. I've checked and it seems that my selected choice in the first dropdown isn't getting passed to the controller.
I did an Alert window and shows "Object object" so no value is getting there.
Can you help see what's wrong with my code?
Thanks.

View:
Code:
[removed]
function getState(){
$("#selectestate").bind("change",function(){

    $("#selectcity").load("results/ajaxcity", {stat: $(this).val()} ); //This is where the problem is
    alert({stat: $(this).val()});//Shows [Object object]
});
return false;

}
[removed]
........
$curstat=$this -> input -> post('state'); //current selected state in first dropdown
<tr>        
    &lt;?php $js = 'id="selectstate" onChange="getState();"';?&gt;
    <td><h3> State: </h3></td>
    <td id="selectestate">&lt;?php echo form_dropdown('state', $stat, $curstat, $js);?&gt;</td>
</tr>    
<tr>    
    <td><h3> City: </h3></td>
    <td id="selectcity">&lt;?php echo form_dropdown('city', $cit);?&gt;</td>
</tr>

Controller
Code:
function  ajaxcity()
{
    
    $stat = $this->input->post('stat');
    $data['searchcity'] = $this->Search->getCity($stat);
    $this->load->view('city', $data);
    
}

Ajax City View:
Code:
&lt;?php foreach($searchcity as $row) :
    $cit[$row->city] = &$row->city;
endforeach; ?&gt;
<td>&lt;?php echo form_dropdown('city', $cit);?&gt;</td>


Messages In This Thread
Get value from selected form_dropdown() - by El Forum - 03-17-2010, 10:09 AM
Get value from selected form_dropdown() - by El Forum - 03-17-2010, 10:17 AM
Get value from selected form_dropdown() - by El Forum - 03-17-2010, 10:34 AM
Get value from selected form_dropdown() - by El Forum - 03-17-2010, 11:04 AM
Get value from selected form_dropdown() - by El Forum - 03-17-2010, 11:13 AM
Get value from selected form_dropdown() - by El Forum - 03-17-2010, 11:27 AM
Get value from selected form_dropdown() - by El Forum - 03-17-2010, 11:32 AM
Get value from selected form_dropdown() - by El Forum - 03-17-2010, 11:34 AM
Get value from selected form_dropdown() - by El Forum - 03-17-2010, 11:36 AM
Get value from selected form_dropdown() - by El Forum - 03-17-2010, 12:13 PM
Get value from selected form_dropdown() - by El Forum - 03-17-2010, 12:17 PM
Get value from selected form_dropdown() - by El Forum - 03-17-2010, 12:24 PM
Get value from selected form_dropdown() - by El Forum - 03-17-2010, 12:36 PM
Get value from selected form_dropdown() - by El Forum - 03-18-2010, 03:01 AM
Get value from selected form_dropdown() - by El Forum - 03-18-2010, 06:38 AM



Theme © iAndrew 2016 - Forum software by © MyBB