I have a view like as
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
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>