get value of selected dropdown list????

#1
[eluser]amira_fcis[/eluser]
how to get the value of selected text from dropdown list that user select from a view and i get it from the controller....here is the view
Code:
<h5>City*</h5>
    <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>
            
            &lt;?}?&gt;
    </select>


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



thanks for help

#2
[eluser]CroNiX[/eluser]
$selected_value = $this->input->post('city'); ??

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

#4
[eluser]CroNiX[/eluser]
Thats what my above posts gives you?

#5
[eluser]amira_fcis[/eluser]
no this echo ids 1,2,3,....
i need values like London,Paris,....

#6
[eluser]Cro_Crx[/eluser]
If you need the names of the cities instead of the ID's then simply set the names of the values.
Code:
<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.....

#7
[eluser]andrewtheandroid[/eluser]
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'));

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

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

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

&& here is the controller
Code:
// 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'];

#8
[eluser]CI_avatar[/eluser]
Code:
$selected_value = $this->input->post('city');
or
$selected_value = $_POST['city'];

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

#9
[eluser]_Moat_[/eluser]
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:
VIEW:
Code:
<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;
</select>

CONTROLLER:
Code:
$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.

#10
[eluser]CroNiX[/eluser]
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.