I am developing the ecommerce website on which i am suck in one place where i am trying to fetch a commission from the sqlserver when admin select the category list and enter price of product , the income of that product what seller will receive should be displayed in another textbox , Here what i have tried till now :
function income_pro(){
var category=document.getElementById("category").options[document.getElementById("category").selectedIndex].value;
var produtprice=document.getElementsByName('productprice')[0].value;
$.ajax({
method: "POST",
url: "get_income.php",
data: {cat_id: "category", price_id: "produtprice"},
success: function(data){
$("#income").html(data); }
});
}
<form>
<select type="text" class="form-control" id="category" required>
<option value="6">Fashion</option>
</select>
<div class="form-group">
<label for="product_name">Product Price After Discount(Selling Price)</label>
<input type="text" class="form-control" name="productprice" onkeyup="income_pro();" id="productprice" placeholder="Enter Product Price" required>
</div>
<div class="form-group">
<label for="product_name">Your Income</label>
<input type="text" class="form-control" name="income" id="income" placeholder="Your Income" disabled>
</div>
</form>
FILE:get_income.php
<?php
include('includes/config.php');
if(!empty($_POST["cat_id"]))
{
$id=intval($_POST['cat_id']);
$price=intval($_POST['price_id']);
$query=mysql_query("SELECT commission FROM category WHERE id=$id");
while($row=mysql_fetch_array($query))
{
$comm = htmlentities($row['commission']); }
$income=$price + ($comm/100)*$price;
}
?>
In database i have an table with the name category and row named commission where the commission of the category is written. Here all the code what i have written but i am not getting any output. Can you please help me out!! It will be great help. Thanks in advance