<form name="expenseFormInline" id="expenseFormInline">
<div class="col-md-8">
<div class="form-group row">
<div class="form-group col-3 md-form"><input id="code" name="code" type="text" class="form-control form-control-sm " aria-label="Code"><label for="code">Code</label></div>
<div class="form-group col-12 md-form"><input id="descNew" name="desc" type="text" class="form-control" aria-label="desc"><label for="desc">Desc</label></div>
<input type="hidden" name="mode" value="expenses">
<input type="hidden" name="FUNCTION" value="save">
<input type="hidden" name="sub" value="expenses">

</form>


 
<script>
$('#popupBox .modal-header').html('<a href="javascript:void(0)" class="sa">New Expense</a>')
$('#popupBox .modal-footer').html('<a id="btnConfirm" href="javascript:void(0)" class="btn btn-info mr-5">Save</a><a id="btnCancel" href="javascript:void(0)" class="btn btn-danger">Cancel</a>');
$("#btnCancel").click(function(){$('#popupBox').modal('hide');})


$("#btnConfirm").click(function(){
var name=$("#expenseFormInline input[name=code]").val();
//alert(reg)
if(name===""){
response('danger','YOU MUST ENTER A CODE');
}
else{$("#expenseFormInline").submit()}
})

$("#expenseFormInline").submit(function(event){
    event.preventDefault();
        $.ajax({
        url:'includes/finance/jump_functions.php',
        type:'POST',
        data:$('#expenseFormInline').serialize(),
        success:function(result){
            
        if($.trim(result)=="s"){
            response('success','Your Expense has been saved successfully');

            var data = {
            id: 999,
            text: $('#descNew').val()
            };
            
            var newOption = new Option(data.text, data.id, true, true);
            parent.$('#type').append(newOption);
            parent.$('#type').select2().trigger('change');
            $('#popupBox').modal('hide')
        }
        else{response('danger','The code is already in the system')}
        }


    });
});

</script>