Welcome Guest, Not a member yet? Register   Sign In
Dropdown set_select problem
#1

[eluser]huzzi[/eluser]
Hi guys!!

I'm having problem setting default value from the database.. here is my code.

View
-------

Code:
<select class="txtNormal" name="age_min">
            <option value="18" &lt;?php echo set_select('age_min', '18'); ?&gt;>18</option>
            <option value="19" &lt;?php echo set_select('age_min', '19'); ?&gt;>19</option>
            <option value="20" &lt;?php echo set_select('age_min', '20'); ?&gt;>20</option>
            <option value="21" &lt;?php echo set_select('age_min', '21'); ?&gt;>21</option>
            <option value="22" &lt;?php echo set_select('age_min', '22'); ?&gt;>22</option>
            <option value="23" &lt;?php echo set_select('age_min', '23'); ?&gt;>23</option>
            <option value="24" &lt;?php echo set_select('age_min', '24'); ?&gt;>24</option>
            <option value="25" &lt;?php echo set_select('age_min', '25'); ?&gt;>25</option>
            <option value="26" &lt;?php echo set_select('age_min', '26'); ?&gt;>26</option>
            <option value="27" &lt;?php echo set_select('age_min', '27'); ?&gt;>27</option>
            <option value="28" &lt;?php echo set_select('age_min', '28'); ?&gt;>28</option>
            <option value="29" &lt;?php echo set_select('age_min', '29'); ?&gt;>29</option>
            <option value="30" &lt;?php echo set_select('age_min', '30'); ?&gt;>30</option>
            <option value="31" &lt;?php echo set_select('age_min', '31'); ?&gt;>31</option>
........
........
</select>

controller
-----------
Code:
$this->form_validation->set_select('age_min', $age_min);

Anything I'm not doing correctly?

Thanks
#2

[eluser]theshiftexchange[/eluser]
This is how I do it:

Code:
<select name="txtNormal"
            <option &lt;?php echo set_select('age_min', '18');?&gt; value="18">18</option>
            <option &lt;?php echo set_select('age_min', '19');?&gt; value="19">19</option>

........
........
</select>
#3

[eluser]huzzi[/eluser]
Does not work.. same as what I have.
[quote author="theshiftexchange" date="1242249762"]This is how I do it:

Code:
<select name="txtNormal"
            <option &lt;?php echo set_select('age_min', '18');?&gt; value="18">18</option>
            <option &lt;?php echo set_select('age_min', '19');?&gt; value="19">19</option>

........
........
</select>
[/quote]
#4

[eluser]davidbehler[/eluser]
Why not use the helper?
Code:
$this->load->helper('form');
$options = array(
                  '18' => '18',
                  '19' => '19',
                  '20' => '20',
                  ...
                );

echo form_dropdown('age_min', $options, set_value('age_min'));
#5

[eluser]theshiftexchange[/eluser]
[quote author="huzzi" date="1242261880"]Does not work.. same as what I have.
[quote author="theshiftexchange" date="1242249762"]This is how I do it:

Code:
<select name="txtNormal"
            <option &lt;?php echo set_select('age_min', '18');?&gt; value="18">18</option>
            <option &lt;?php echo set_select('age_min', '19');?&gt; value="19">19</option>

........
........
</select>
[/quote][/quote]

Just to be sure: you realise my code is DIFFERENT to your code right? It is not the same.

My "set_select" is right after the <option field. I had the same problem as you a week ago, and by moving set_select it fixed my issue.
#6

[eluser]Thorpe Obazee[/eluser]
@OP don't you need to set the third parameter of set_select() to TRUE to select anything you have in the database?
#7

[eluser]neversummer[/eluser]
I am having a similar problem with set_select. I've read the set_select bit in the user guide about 30 times now, and have searched the forums, but still can't get my dropdown to set the value.

I have a simple html select control:
Code:
<select name="state">
  <option value="">Select State...</option>
  <option value="AL" &lt;?php echo set_select('state', 'AL'); ?&gt; >Alabama </option>
  <option value="AK" &lt;?php echo set_select('state', 'AK'); ?&gt; >Alaska </option>
  <option value="AB" &lt;?php echo set_select('state', 'AB'); ?&gt; >Alberta </option>
  <option value="AZ" &lt;?php echo set_select('state', 'AZ'); ?&gt; >Arizona </option>
  <option value="AR" &lt;?php echo set_select('state', 'AR'); ?&gt; >Arkansas </option>
...
</select>
my controller is pulling the value from the db, and I'm confident that is working b/c I can set the value on a hidden input.

Any suggestions on what I am doing wrong? BTW, I did try moving the value="" after the echo statement and that proved fruitless. I should add that I'm not getting any errors, the page loads and paints fine, it's just that the control is not getting set.

thanks, mike
#8

[eluser]Unknown[/eluser]
Hi All,

I was having the same problem. Turned out I wasn't yet setting a validation rule. If you don't use set_rules(), like:

Code:
$this->form_validation->set_rules('fieldname', 'Field name', 'required');

on the select list, set_select() won't work properly.




Theme © iAndrew 2016 - Forum software by © MyBB