CodeIgniter Forums
jQuery form serialize data missing in CodeIgniter - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: jQuery form serialize data missing in CodeIgniter (/showthread.php?tid=56790)



jQuery form serialize data missing in CodeIgniter - El Forum - 01-20-2013

[eluser]Unknown[/eluser]
i have a form in my view page .....as i want to send data through jquery or ajax because i dont want to reload or refresh the page . i am sending data through jquery serialize.. but all the fields are not submitting through serialize.. here first dropdown which is "supplier" is going empty .. means jquery serialize is not capturing his value //..

Code:
<?php  echo form_open('stockInController/addStockIn', $attributes);
   ?>


   <!-- Supplier -->

  
    Select a Supplier
    
     <select name="sup_id" id="sup_id" class='cho'>
      <option id="y" value="0">--Select--</option>
      &lt;?php foreach($records1 as $r) { ?&gt;
      <option value="&lt;?=$r-&gt;sup_id?&gt;">
       &lt;?=$r->sup_name?&gt;
      </option>
      &lt;?php } ?&gt;
     </select>
    
   &lt;!-- end of Supplier --&gt;

    

   Date:&lt;?php echo form_input($date); ?&gt;
                        Bill No: &lt;?php echo form_input($bill_no); ?&gt;
    
            
    

     <table>
      <tr>
       <th>Category:</th>
       <th>Items:</th>
       <th>Selling Price:</th>
       <th>quantity:</th>
       <th>total:</th>
      </tr>
      
            &lt;?php for ($i = 0; $i < 5; $i++) {

       ?&gt;
      <tr>
<td>&lt;?php echo form_dropdown('cat_id'.$i, $records2, '#',     "id='category_".$i."' onchange='getItems(this.value,".$i.")' ");?&gt;
       </td>
    

                      

<td> &lt;?php echo form_dropdown('item_id'.$i, $records3, '$var', "id='items_".$i."'"); ?&gt;

       </td>
        



    <td>&nbsp; &lt;input type="text" name = "price_&lt;?php echo $i ?&gt;" id = "price_&lt;?php echo $i ?&gt;"   echo "$i"?&gt;)'&gt;
       </td>

  <td>&nbsp; &lt;input type="text" name = "quantity_&lt;?php echo $i ?&gt;" id = "quantity_&lt;?php echo $i ?&gt;"  echo "$i"?&gt;)'&gt;
       </td>
      
       <td>&nbsp; &lt;input type="text" name = "total_&lt;?php echo $i ?&gt;" class = "input-small input-square" id = "total_&lt;?php echo $i ?&gt;"&gt;
       </td>
      </tr>
      

      &lt;?php }?&gt;
    
      <tr><td>
      <br>
        &lt;?php echo form_button($button); ?&gt;
        &lt;?php form_close();?&gt;
       </td></tr>

here is my jquery function ..


Code:
$('#btn').click(function(event) {
        form = $("#form").serialize();

      $.ajax({
        type: "POST",
        url: "&lt;?php  echo site_url('stockInController/addStockIn'); ?
        data: form,

        success: function(data){
         $(".success").fadeIn(500).delay(2000).fadeOut(500);
         $("#form")[0].reset();
      
        }

      });
      event.preventDefault();
      return false;

   });



jQuery form serialize data missing in CodeIgniter - El Forum - 01-21-2013

[eluser]Otemu[/eluser]
Follow this guide http://api.jquery.com/serialize/


jQuery form serialize data missing in CodeIgniter - El Forum - 01-21-2013

[eluser]vitoco[/eluser]
This is by far more quickly and clean . Jquery form plugin

http://malsup.com/jquery/form/


Slds