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

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?

Something link this:
<?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" />

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

http://api.jquery.com/jQuery.ajax/ is probably what you're looking for.

[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.

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:


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?

function getState(){

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

$curstat=$this -> input -> post('state'); //current selected state in first dropdown
    &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>
    <td><h3> City: </h3></td>
    <td id="selectcity">&lt;?php echo form_dropdown('city', $cit);?&gt;</td>

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

Ajax City View:
&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