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

[eluser]bondjp[/eluser]
You're right, i was just reading about it...

Well what i want to do next is build an url with this and other data that's ready and have a button to pass the data to my controller where i will use uri->element(id) and save the values to the several dbs that i have.
How can i proceed to do this?
what's the best way?
#12

[eluser]bondjp[/eluser]
Something link this:
Code:
<?php $confirm='controller/method/'.$time.'/'.$name.'/'.$why;?>
<a  href="&lt;?php echo  base_url().$confirm;?&gt;" rel="nofollow">
<img src="&lt;?php echo base_url();?&gt;images/confirm.png" border="0" />
</a>

$why is what i will append to my url...
#13

[eluser]danmontgomery[/eluser]
http://api.jquery.com/jQuery.ajax/ is probably what you're looking for.
#14

[eluser]dark_lord[/eluser]
[quote author="bondjp" date="1268865411"][quote author="WishBear*" date="1268865245"]Workaround?

alert(x.selectedIndex + 1);[/quote]

Ok the value starts at 0 so no need to work around :)...

Now how can i pass this value and use it in my php code?[/quote]

I thought you'll just need the value inside a form, not passing it to PHP Code, hehe.. anyway, you might need Ajax for that to be able to pass the client side variable to the server side, I agree with the folks that help you out also here.
#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>




Theme © iAndrew 2016 - Forum software by © MyBB