CodeIgniter Forums
Re-populate checkboxes - 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: Re-populate checkboxes (/showthread.php?tid=43833)



Re-populate checkboxes - El Forum - 07-25-2011

[eluser]zxcv[/eluser]
I have a form where a user fills in a reportform. The report is availible for edit, it retrieves the information from the database and shows the same form but with the previous information. However checkboxes and dropdownmenus are not re-populated, how do I make them set "automatically"?

Thank you
zxcv


Re-populate checkboxes - El Forum - 07-25-2011

[eluser]samitrimal[/eluser]
try
Code:
For checkbox
<input type='checkbox' value='2'<?php if($data['something']=='2'){?>checked<?php };?>>
For select
Code:
<select>
<option value=1>1</option>
<option value=2 &lt;?php if($data['something']=='2'){?&gt;checked&lt;?php }?&gt;>2</option>
</select>

If it doesnt work show ur source code


Re-populate checkboxes - El Forum - 07-25-2011

[eluser]Kamarg[/eluser]
If you're using the form helper functions (form_dropdown, form_checkbox, etc) you can pass a default value to them that will automatically select/check the correct items.


Re-populate checkboxes - El Forum - 07-25-2011

[eluser]Unknown[/eluser]
nice information.. Thanx