get value of selected dropdown list????

how to get the value of selected text from dropdown list that user select from a view and i get it from the is the view
    <select name="city">
            <option value="0">select city</option>
            &lt;? foreach($city as $ci){?&gt;
                 <option value="&lt;? echo $ci['id'] ;?&gt;">&lt;? echo $ci['name'];?&gt;</option>

&& here is the controller
// here i need to make echo for selected value of city dropdown list.

thanks for help

$selected_value = $this->input->post('city'); ??

many thanks ,but what if i need the value of option like 1,2,3 depending on the selected item of course.
<option value="&lt;? echo $ty['id'] ;?&gt;"></option>

Thats what my above posts gives you?

no this echo ids 1,2,3,....
i need values like London,Paris,....

If you need the names of the cities instead of the ID's then simply set the names of the values.
<option value="&lt;? echo $ci['name'] ;?&gt;">&lt;? echo $ci['name'];?&gt;</option>
Or you could look them up using the ID against stored database values or a preset array etc.....

may i suggest storing $city as an array with $cities = array('id'=>'name');

Or if you need to store information other than name instead of name you could have an array

$cities = array('id'=>array('name'=>'paris','location'=>'france','population'=>'lots'));

&lt;? foreach($cities as $id => $city_name){>

                 <option value="&lt;? echo $id;?&gt;">&lt;? echo $city_name;?&gt;</option>

               // OR if you used the second option
               foreach ($cities as $id => $properties)
                   echo '<option value="'.$id.'">'.$properties['name'].'</option>';

&& here is the controller
// here i need to make echo for selected value of city dropdown list.
$id = $this->input->post('city'); // The value will be the id array index

// to display the one you want
$selected_city = $cities['id'];
// OR second option
$selected_city = $cities['id']['name'];

$selected_value = $this->input->post('city');
$selected_value = $_POST['city'];

is the correct one. please check the values of your array.

i know this is an old topic but i have a problem where the post is not retrieving the value of the selected option.

what i'm doing is:
<select name="ID">
<option value="0">Chose a Category</option>
&lt;?php $i = 0; foreach ($frm1_ctg as $key) { ?&gt;
<option value="&lt;?php echo set_value() == "" ? $frm1_ctg[$i]['ID'] : set_value('ID');?&gt;">&lt;?php echo $frm1_ctg[$i]['CATEGORY_NAME'];?&gt;</option>
&lt;?php $i++;} ?&gt;

$selected_Val = $this->input->post('ID');
and all my options is filled from db which works fine, and the same if i used an input.
the value of the $selected_Val= 0 and it never changes if the the option changed.

How many times are you going to ask the exact same question and ignore the solutions?

You are not using set_value() correctly. It requires at least one parameter, the field name to get the value of.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.