0

This function is called when I submit the page if the record exits I want page will not submit .. But it is not working..

   function checkvalidation(){

        var err=true;
        var party_id = $('#party_id').val();            
        var item_id = $('#item_id').val();
        var typ =$('#type').val();                  

        $.post("<?= base_url() ?>checkduplicate.php?item="+item_id+"&party="+party_id+"&type="+typ,function(r){
            if(r != "")
            {
                err = false;


            }
        });

        return err;
    }
Pippi
  • 313
  • 1
  • 4
  • 18
Anamika
  • 1
  • 2

1 Answers1

0

You can try this

var party_id = $('#party_id').val();            
var item_id = $('#item_id').val();
var typ =$('#type').val();  
var jqxhr = $.post( "<?= base_url() ?>checkduplicate.php?item="+item_id+"&party="+party_id+"&type="+typ, function() {
  alert( "success" );
})
  .done(function() {
    alert( "second success" );
  })
  .fail(function() {
    alert( "error" );
  })
  .always(function() {
    alert( "finished" );
});

but when this function is called, it execute submit. If you want to check the parameters you can try this

function checkParam(param){
 return typeof param != 'undefined' && param != null;
};
function checkvalidation(){
var party_id = $('#party_id').val();            
var item_id = $('#item_id').val();
var typ =$('#type').val();  

if(checkParam(party_id) && checkParam(item_id) && checkParam(typ)){
 var jqxhr = $.post( "<?= base_url() ?>checkduplicate.php?item="+item_id+"&party="+party_id+"&type="+typ, function() {
 alert( "success" );
})

}else{
 //code
 return;
}

}

Pippi
  • 313
  • 1
  • 4
  • 18