[eluser]veritascs[/eluser]
I'm newish to javascript and having a little trouble. I got the AJAX part down, I just don't know how to handle the returned array in JS (or maybe I'm passing it incorrectly from CI).
Anyway, here is my JS (using jQuery):
Code:
function getCat(obj) {
var catID = obj[obj.selectedIndex].value;
$.post("categories/getCat", { category_id: catID },
function(data){
formObject = document.forms['modify_category'];
formObject.elements['category_name'].value = data["category_name"];//THIS IS WHERE IM SUCK
});
}
My controller:
Code:
function getCat() {
$category = $this->category_model->getCategoryInfo($this->input->post('category_id'), 'category_id');
echo $category;
}
And my model:
Code:
function getCategoryInfo($category, $column_name = 'category_id') {
$query = $this->db->get_where('categories', array($column_name => $category));
$row = $query->row();
return $row;
}