Welcome Guest, Not a member yet? Register   Sign In
Dropdown default value
#1

[eluser]Ninja[/eluser]
Controller
Code:
$client = new Client();
            $client->get('id');
    
            foreach($client->all as $entry)
            {
                $clientID = $entry->id;
                $entry->company->get('companyname');
                $companyName = $entry->company->companyname;
                $data['parent'][$clientID] = $companyName;    
            }

View
Code:
<?php echo form_dropdown('Parent', $parent )?>

Im trying to set the default value for the dropdown to something like "Not Applicable"
With an index of 0. This dropdown is for Parent clients (ie. The client of a client) but not all clients will have a parent client.
#2

[eluser]steelaz[/eluser]
Assuming "Not Applicable" option index is 0:

Code:
<?= form_dropdown('Parent', $parent, 0)?>


Also... wrong forum, next time try: Code and Application Development
#3

[eluser]davidbehler[/eluser]
If you use the form validation, you could use the set_value function:
Code:
<?= form_dropdown('Parent', $parent, set_value('Parent', 0))?>

That way the default value is 0 but if the form was submitted and did not validate, the selected value will be kept instead of resetting it to 0.
#4

[eluser]Ninja[/eluser]
I have tried both of those options but i think the problem is that "Not Applicable" with index 0 is not in the array and i cant seem to add it to the array.. The array is being populated from the database table clients. which has 3 fields id, parent_client, company_id.
#5

[eluser]Thorpe Obazee[/eluser]
Deja vu http://ellislab.com/forums/viewthread/123388/
#6

[eluser]Ninja[/eluser]
Problem solved thanx guys




Theme © iAndrew 2016 - Forum software by © MyBB