Im trying to add to dropdowns without having to leave the page. i have read THIS, but cant figure out what to change, what is the table structure ....
** The view code :
<link rel="stylesheet" href="<?=base_url()?>assets/plugins/fancybox/jquery.fancybox.css?v=2.0.6" type="text/css" media="screen" />
<script type="text/javascript" src="<?=base_url()?>assets/plugins/fancybox/jquery.fancybox.pack.js?v=2.0.6"></script>
<script type="text/javascript">
$(document).ready(function() {
$(".various").fancybox();
//ADD IN A BUTTON TO ADD TO DROPDOWN
$('#countryID_input_box').append('<a href="<?=site_url()?>/examples/quick_add/" class="various fancybox.ajax">Add</a>');
});
</script>
** The controler code:
function quick_add()
{
//EDIT BELOW TO ADD YOU SELECT NAME VALUE
$args = array(
'category_name' => 'select[name="countryID"]'
);
$javascript = '
<script>
function do_quick_add()
{
var category_text = $(\'#category_item\').val();
var category_id = $(\''.$args['category_name'].'\').val();
$.post(\''.site_url().'/examples/quick_add_save/\', { categoryID: category_id, category_item: category_text }, function(data) {
//PREPEND DATA TO SELECT BOX
$(\''.$args['category_name'].'\').prepend(\'<option value="\'+data+\'">\'+category_text+\'</option>\');
//REBUILD SELECT BOX
$(\''.$args['category_name'].'\').trigger("liszt:updated");
//DISPLAY SUCCESS MESSAGE
$(\'#category_message\').html(\'Successfully inserted a new category\');
});
}
</script>
';
$html = '
<div style="width: 400px; height: 250px;">
<div style="padding: 5px;">New Category Name:</div>
<div style="padding: 5px;"><input type="text" name="category_item" id="category_item"></div>
<div style="padding: 5px;"><input type="button" value="Add »" onclick="do_quick_add();"> <span id="category_message"></span></div>
</div>
';
echo $javascript.$html;
exit;
}
function quick_add_save()
{
//POST ITEMS
$categoryID = $this->input->post('categoryID', true); //only needed if adding a sub category, can get parent ID
$category_text = $this->input->post('category_item', true);
//SAVE TO DATABASE
$data = array(
'country_title' => $category_text
);
$this->db->insert('country', $data);
return $this->db->insert_id();
}
Can someone tell me what is the structure of the table in that code, i dont understand what i need to modify to make it work.