CodeIgniter Forums

Full Version: Database operation In Jquery
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Rahul gamit[/eluser]
I am using select dropdown html control and one textbox,
I have used onchange() event of select dropdown control to fill the text box value,

this is the code
<select id="cmb_fruit" name="cmb_fruit">
<option value="1">Apple</option>
<option value="2">Mango</option>
<option value="3">Orange</option>

&lt;input type="text" id="txt_fruit" name="txt_fruit"/&gt;


$(function() {
   $('#cmb_fruit').change( function() {

so this code will fill the value whenever the value of the dropdown is changed,
And i want to perform database operation whenever the data is changing ,
for example: if i select fruit i am having the value apple i want to select data from the database, so how can i perform codeigniter database operation in jquery?

thanks in advance .

El Forum

I will generally make a AJAX handler in my controller. Using jQuery inside of your change event use post to post the values to your controller to update the db.

  var form = $("form[name='your_form_name']").serialize();
  $.post('&lt;?php echo site_url('controller/jquery_handler');?&gt;',form, function(data){
    //maybe do something with json here

function jquery_handler(){
  $this->form_validation->set_rules('cmb_fruit', 'fruit', 'required|trim');

   if( $this->form_validation->run() ){
      $data['fruit'] = $this->input->post('cmb_fruit');
      //Do a query here