⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

listbox selected item on callback



gavin1211

gavin1211
  • profile picture
  • Member

Posted 21 April 2012 - 08:51 AM

How do you maintain the selected option on a select box in edit view, when I am using a callback. The code I am using below is:



function colour_callback()
{
return '<select name="colour" id="colour">
<option value="null">Please select</option>
<option value="Beige">Beige</option>
<option value="Black">Black</option>
<option value="Blue">Blue</option>
</select>
';
}



Thanks.

web-johnny

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 21 April 2012 - 09:29 AM


function colour_callback($value = '')
{
$this->load->helper('form');
$options = array('' => 'Please select', 'Beige' => 'Beige' , 'Black' => 'Black', 'Blue' => 'Blue');
return form_dropdown('colour', $options, $value,"id='color'");
}


P.S. Please add the code tags when you add code (php/javascript/html or whatever) the next time: [attachment=117:tag-code.png]. Thank you

gavin1211

gavin1211
  • profile picture
  • Member

Posted 21 April 2012 - 09:37 AM

Thanks, that worked beautifully.