Welcome Guest, Not a member yet? Register   Sign In
set_select problem in setting default values from db
#1

[eluser]Jygz V[/eluser]
Hi,

Good day.

I am new to CI, I was confused on how to set default values of a dropdown using the "set_select".

This is the scenario.

I have a page with the following dropdown:
<select name='gender'>
<option name='male'>Male</option>
<option name='female'>Female</option>
</select>

And when this page is loaded, I get the gender from the database based from the user's profile. The gender drop down will be set to default depending on what gender is retrieved from the database. Can anybody show me how to do that using "set_select"?

Thanks.
#2

[eluser]xzela[/eluser]
Hi,

This is what I do to determine which select field to use. It may not be the 'proper' way to do it, however it works for me.

Code:
<select name='gender'>
    &lt;?php if(set_value('gender') == 'Male'):?&gt;
        <option value='male' selected >Male</option>
        <option value='female'>Female</option>
    &lt;?php else: ?&gt;
        <option value='male'>Male</option>
        <option value='female' selected>Female</option>
    &lt;?php endif;?&gt;
</select>

This probably isn't the best way to do it now that i think about it. I typically have a foreach loop to loop through all the options and use an if statement to determine the default selection.

I don't know, just a suggestion... Smile
#3

[eluser]Jygz V[/eluser]
Thanks for your response. My default value came from the database, how will I do that? Thanks.
#4

[eluser]Future Webs[/eluser]
this comes up all the time

http://ellislab.com/forums/viewthread/97495/

thats a post where i had the same problems




Theme © iAndrew 2016 - Forum software by © MyBB