jquery ajax call in onsubmit function is not working
- by shilna mk
I have form submission page add_sale.php and an ajax page ajx_check_sale.php.Ajax call is inthe onsubmit function.But ajax is not worikng.Anybody give any solution plz..
I have form submission page add_sale.php and an ajax page ajx_check_sale.php.Ajax call is inthe onsubmit function.But ajax is not worikng.Anybody give any solution plz..
add_sale.php
function sale_credit(id)
{
var cust_name=$('#cust_name').val();
$.ajax({
type: "POST",
url: 'ajx_typ1.php',
data:'id='+id,
success: function(msg)
{
$("#sale_type1").html(msg);
}
});
$.ajax({
type: "POST",
url: 'ajx_typ3.php',
data:'id='+id,
success: function(msg)
{
$("#sale_type3").html(msg);
}
});
$.ajax({
type: "POST",
url: 'ajx_typ2.php',
data:'id='+id,
success: function(msg)
{
$("#sale_type2").html(msg);
}
});
}
function validate_form()
{
var cust_name= $('#cust_name').val();
var total= $('#total').val();
var sale_type= $('#sale_type').val();
if(sale_type=='return')
{
$.ajax({
type: "POST",
url: 'ajx_check_sale.php',
data:'cust_name='+cust_name + '&total=' + total,
success: function(msg)
{
alert(msg);
/*if(msg==0)
{
alert("Return is greater then sale");
return false;
} */
}
});
}
}
<form action="" method="post" name="adFrm" onSubmit="return validate_form()">
<select name="sale_type" style="width:130px;"
id="sale_type" onchange="sale_credit(this.value)" >
<option value="">Select</option>
<option value="credit">Credit</option>
<option value="payment">Payment</option>
<option value="return">Return</option>
</select>
</form>
ajx_check_sale.php
require_once("codelibrary/inc/variables.php");
require_once("codelibrary/inc/functions.php");
echo $cust_name=$_POST['cust_name'];
echo $return=$_POST['total'];
$cus="select sum(total) as total_sum from customer where id='$cust_id'";
$cus2=mysql_query($cus);
$fet=mysql_fetch_array($cus2);
$total=$fet['total_sum'];
if($return>$total)
{
$status=0;
echo $status;
}
else
{
$status=1;
echo $status;
}