Dropdown default value - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: Dropdown default value (/showthread.php?tid=20633) |
Dropdown default value - El Forum - 07-16-2009 [eluser]Ninja[/eluser] Controller Code: $client = new Client(); 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. Dropdown default value - El Forum - 07-16-2009 [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 Dropdown default value - El Forum - 07-16-2009 [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. Dropdown default value - El Forum - 07-17-2009 [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. Dropdown default value - El Forum - 07-17-2009 [eluser]Thorpe Obazee[/eluser] Deja vu http://ellislab.com/forums/viewthread/123388/ Dropdown default value - El Forum - 07-17-2009 [eluser]Ninja[/eluser] Problem solved thanx guys |