![]() |
form_dropdown and selected - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: form_dropdown and selected (/showthread.php?tid=17932) |
form_dropdown and selected - El Forum - 04-20-2009 [eluser]nealumney[/eluser] I have an array of items I want to include as a 'drop down' and so I have (within my view) the following code: echo form_dropdown('manufacturer', $mftrs); all is well and presents a list of manufacturers for the user to select from. However, I need the first item to be a 'Please select ... ' item, and have this as an entry in the $mftrs' array. What I want to do is to have this 'selected' rather than just appear in the list somewhere. I could of course manually do the following: <select name="manufacturer"> <option value="">Please select ...</option> <?php foreach ($mftr $key as $row) { ?> <option value="<?php echo $key ;?>" ><?php echo $row ; ?></option> <?php } ?> </select> Is there anyway of using the form_dropdown method with an array to choose the selected item? Thanks, Neal form_dropdown and selected - El Forum - 04-20-2009 [eluser]The Wizard[/eluser] hello, there is a workarround i frequently use, just a sec. form_dropdown and selected - El Forum - 04-20-2009 [eluser]The Wizard[/eluser] Code: function Dropdown_CreditCard( $name, $user_id, $selected_id = '', $reload = FALSE ) thats the code and Code: // in validation that would be the use of it. i hope it helps form_dropdown and selected - El Forum - 04-20-2009 [eluser]slowgary[/eluser] This is another reason why I don't really get using helpers to generate markup. The markup is so simple to begin with, does it really simplify anything? What's the benefit? If you MUST do it this way, a crappy hack could be to just use JavaScript to insert the first element... Code: < script type='text/javascript' > This example uses jQuery form_dropdown and selected - El Forum - 04-20-2009 [eluser]Asinox[/eluser] Well my way: Code: function listCombox(){ //COMBOX |