CodeIgniter Forums
What is the easiest way of reselecting the selected value - 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: What is the easiest way of reselecting the selected value (/showthread.php?tid=21660)



What is the easiest way of reselecting the selected value - El Forum - 08-17-2009

[eluser]Neeraj Kumar[/eluser]
Hi all!

I have been working with form validation helper.

I want to know that what would be the easiest way of re selecting the selected value posted via form submission.

Adding a check to every <option> is not a good idea, especially for big lists.

Code:
<select name="test" id="course_type">
    <option value="1" &lt;?php (set_value('test') == '1')? 'selected': '' ; ?&gt;>first</option>
    <option value="2" &lt;?php (set_value('test') == '2')? 'selected': '' ; ?&gt;>Second</option>
    <option value="3" &lt;?php (set_value('test') == '3')? 'selected': '' ; ?&gt;>Third</option>
</select>



What is the easiest way of reselecting the selected value - El Forum - 08-17-2009

[eluser]pistolPete[/eluser]
Have a look at the user guide: http://ellislab.com/codeigniter/user-guide/helpers/form_helper.html
Quote:set_select()

If you use a <select> menu, this function permits you to display the menu item that was selected. The first parameter must contain the name of the select menu, the second parameter must contain the value of each item, and the third (optional) parameter lets you set an item as the default (use boolean TRUE/FALSE).



What is the easiest way of reselecting the selected value - El Forum - 08-17-2009

[eluser]Neeraj Kumar[/eluser]
thanks for pointing out, I mis understood the procedure.. Smile