Welcome Guest, Not a member yet? Register   Sign In
Weird Problem with form_dropdown default selected value
#1

[eluser]NachoF[/eluser]
Im trying to have a value already selected when the user comes inside a form cause it is an edit form.
Code:
$options = array(
                  '0'  => 'Low',
                  '1'    => 'Medum',
                  '2'   => 'High',
                );
echo $task->priority;
echo form_dropdown('priority',$options,$task->priority)?>
As you can see Im echoing the default value just to make sure Im getting it right.. and I am, the value gets printed out right before the dropdown, but the dropdown doesnt use that default value... yet if I try
Code:
$options = array(
                  '0'  => 'Low',
                  '1'    => 'Medum',
                  '2'   => 'High',
                );
echo form_dropdown('priority',$options,2)?>
It does put High as already selected... we cant use variables in the helper or what?
$task->priority is just a value that I get from database.. if it makes a difference its set to ' character(20)" in the database... I didnt create it so I cant change it. another app dependes on the same databse.
#2

[eluser]Kenneth Allen[/eluser]
There are two possibilities that come to mind.

First is that the key value is to be passed to the dropdown call, not the display value. When you echo are you seeing the key value or the display name for that value?

The second is that upon occasion I have encountered places where I had to save the result to a local variable and then act upon that value. I do not know why this happens as I have not noticed a specific pattern. Try that and see if it makes a difference.
#3

[eluser]Kamape[/eluser]
Have you tried var_dump() your value? If you're having char instead of varchar maybe you'll have to trim() your value or else it will not be the same string.

'2' isn't the same as '2 '.
#4

[eluser]NachoF[/eluser]
[quote author="Kamape" date="1246925930"]Have you tried var_dump() your value? If you're having char instead of varchar maybe you'll have to trim() your value or else it will not be the same string.

'2' isn't the same as '2 '.[/quote]
awesome!
trim() worked!




Theme © iAndrew 2016 - Forum software by © MyBB