I am creating this simple project that includes auto calculate of the price and quantity and then display it only after two < select > tags has been triggered,set or selected using AJAX without using submit button. I can achieve this but does not automatically calculates and display it without using submit button.
this is my code in HTML:
<form method="post">
    <select name="days">
        <option value="2">2 days</option>
        <option value="3">3 days</option>
    </select>
    <select name="persons">
        <option value="2">2 persons</option>
        <option value="4">4 persons</option>
        <option value="6">6 persons</option>
        <option value="8">8 persons</option>
    </select>
</form>
Assume that in my Database
day 2 == 1000
day 3 == 2000
this is my code in PHP:
if(isset($_POST['submit'])) {
    $days     = $_POST['days'];
    $persons  = $_POST['persons'];
    // get database of the 'price' from rates tbl 
    $sql = "SELECT * FROM rates WHERE duration='$days'";
    $res = mysqli_query($conn,$sql);
        $rates_tbl = mysqli_fetch_assoc($res);
    $rates = $rates_tbl['price'];
    $total_price = ($rates*$persons);
    echo 'total: ' . number_format($total_price) . '.00';
}
Should i use this type of ajax?? I dont even know if this is right.
    <script type="text/javascript"> 
       $.ajax({  
            url:"autocalculate.php",  
            method:"POST"
       }) 
    </script>
 
    