[eluser]Unknown[/eluser]
Hi there, have been working on this problem far too long so have signed up for some help.
I am trying to create a dropdown form with countries populated from a database. I need to get the chosen countries ID and store it into another table on the DB. So far i have created the dropdown but have no idea how to use JQuery to get ID from the list.
Any help would be appreciated.
VIEW:
<?php
$attributes = array('class' => 'profile_textbox_disabled', 'id'=> 'country_select', 'disabled' =>'disabled');
echo form_open('', $attributes);
echo form_dropdown('countries', $select_country);
?>
<a href="#" id="country_select_edit"><img src="<?php echo base_url(); ?>assets/images/edit.png" alt="Edit" ></a>
<span id="country_select_ajax_reply" class="notify"></span>
<?php
echo form_close();
?>
JQuery:
$("#country_select_edit").click(function () {
$('#country_select').addClass('profile_textbox_enabled').removeAttr("disabled")
.change(function () {
$.ajax({
type: "POST",
url: "calls/countries_list/",
//data: "data=" + $(this).val(), //These are other methods i've tried.
//data: "country_name="+$('#country_select').val(), //These are other methods i've tried.
data: "country_name="+this.value+"&id;="+<?php echo $this->session->userdata('user_id'); ?>,
complete: function(data){
//print result in targetDiv
$('#country_select_ajax_reply').html(data.responseText);
}
});
$('#country_select').removeClass('profile_textbox_enabled').attr("disabled", "disabled");
});
});
MODEL:
$query = $this->db->query("
SELECT country_id, country_name
FROM countries
");
foreach($query->result_array() as $row)
{
$data[$row['country_id']]=$row['country_name'];
}
return $data;
CONTROLLER (for JQuery)
function countries_list()
{
$message = $_POST['country_name'];
//echo $_POST['data'];
echo $message;
}
Am using $message to trial and error the code to try get a value returned. At the moment i keep getting undifined.