0

I have a view like as enter image description here

There are two option. One is Order Name. Second is Operation Type[Add Invoice, Add Shipment]

When I will select Add Invoice an ajax call will make and added add_invoice.php to here,this page contains some input field like as enter image description here

The first page's script codes are:

        <script>
            $(function(){
                 $('#operation_id').change(function(e){
                          var order_id = $('#order_id').val().trim();
                          var operation_id = $('#operation_id').val().trim();
                          if (order_id !='' && operation_id !='') {
                               url = '<?php echo site_url()?>/order/orderProcessing';
                               $.post(url,
                    {order_id:order_id,operation_id:operation_id},function(data){
                     $('.dataprocess').html(data);
                     $('.datepicker').datepicker();
                   });
                }
             else{
                   alert('Select both fields.');
                   e.preventDefault();
                 }
             });
          });
       </script>

Now, I want to validate the input field of add invoice page. For making this I have made the add_invoice page as give below but it is not working. Could you help me ?

    <script>
   $('#submit').click(function(em){
        var invoice_number = $('#invoice_number').val().trim();
        var invoice_date = $('#invoice_date').val().trim();
        var quantity = $('#quantity').val().trim();
        var shipment_st = $('#shipment_st').val().trim();
        if (quantity !='' && invoice_number !='' && invoice_date !='' && shipment_st
                !='') {
            $('form #add_invoice').submit();
        }
        else{
            alert('Empty fields can not be sent');
            em.preventDefault();
        }
   });
  </script>
    <h2>Add Invoice</h2>
    <?php
       $attributes = array('id'=>'add_invoice','enctype'=>"multipart/form-data");
        echo form_open('/order/addInvoice?id='.$id,$attributes);
     ?>
     <dl>
         <dt>Invoice Number</dt>
         <dd><?php
          $invoice_number = array(
                'name'=> 'invoice_number',
                'type' => 'varchar',
                'id'=> 'invoice_number',
                 'required'=> 'required',
                 'value' => set_value('invoice_number')
           );
          echo form_input($invoice_number).'MT';
          echo '<span style=color:red>'.form_error('invoice_number').'</span>';
         ?>
        </dd>
        <dt>Invoice Date</dt>
             <dd><?php
                $invoice_date = array(
                     'name'=> 'invoice_date',
                     'type' => 'date',
                      'id'=> 'invoice_date',
                      'class'=> 'datepicker',
                      'required'=> 'required',
                       'value' => set_value('invoice_date')
                 );
                 echo form_input($invoice_date);
                 echo '<span style=color:red>'.form_error('invoice_date').'</span>';
                ?>
              </dd>
              <dt>Quantity</dt>
               <dd><?php
                      $quantity = array(
                               'name'=> 'quantity',
                                'type' => 'varchar',
                                'id'=> 'quantity',
                                 'required'=> 'required',
                                 'value' => set_value('quantity')
                             );
                               echo form_input($quantity).'MT';
                               echo '<span  style=color:red>'
                                  .form_error('quantity').'</span>';
                              ?>
                            </dd>
                           <dt>Shipment Status</dt>
                               <dd><?php
                                        $shipment_st =
                                             array(''=>'','1'=>'Shipped','0'=>'Yet not 
                                                       shipped');
                                                      $js = 'id="shipment_st"';
                                                  echo 
                                     form_dropdown('shipment_st',$shipment_st,$js)?>
                                </dd>
                                <dd><?php
                                      $submit = array(
                                             'id' => 'submit',
                                              'type' => 'submit',
                                                'value' => 'Add'
                                        );
                                       echo form_submit($submit)?>
                                      </dd>
                                   <?php echo form_close()?>
                                    </dl>
Kabir Hossain
  • 2,865
  • 1
  • 28
  • 34
  • 1
    script #submit function you have to put in parent page (it's first page) – Ryan Nghiem Oct 25 '14 at 09:17
  • Try wrapping the script for the second page in a `$(document).ready();` function – Michael Smith Oct 25 '14 at 09:19
  • I think you mean validation *before* the Ajax call. And that is what your code is trying to do. Also, your set ever side code needs to do validation as well. – Jeff Oct 25 '14 at 09:23
  • I need to validate the second form data.When a user will click to submit the second form, the jquery will check the form input field, so that user can not submit empty input field. – Kabir Hossain Oct 25 '14 at 09:35

0 Answers0