Make a GST Calculator using HTML and JavaScript

 Make a GST Calculator using HTML and JavaScript 


HTML
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <table>
        <tr>
            <td>Product Name</td>
            <td>
                <input type="text" id="pn">
            </td>
        </tr>
        <tr>
            <td>Product Price</td>
            <td>
                <input type="text" id="pp">
            </td>
        </tr>
        <tr>
            <td>Product Quantity</td>
            <td>
                <input type="text" id="pq">
            </td>
        </tr>
        <tr>
            <td>Rate</td>
            <td>
                <select name="" id="rate">
                    <option value="5">5%</option>
                    <option value="12">12%</option>
                    <option value="18">18%</option>
                    <option value="28">28%</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>Intrasate/InterState</td>
            <td>
                <select name="" id="ps">
                    <option value="0">Intrasate</option>
                    <option value="1">InterState</option>
                  
                </select>
            </td>
        </tr>
        <tr>
            <td>
                <button onclick="gstCalc()">Calculate GST</button>
            </td>
        </tr>
    </table>
    <table>
        <tr>
            <td>Product Name</td>
            <td>Product Price</td>
            <td>Product Quantity</td>
            <td>Amount</td>
        </tr>
        <tr id="tr1">

        </tr>
        <tr id="tr2">

        </tr>
        <tr id="tr3">

        </tr>
        <tr id="tr4">

        </tr>
    </table>
    <script src="code.js"></script>
</body>
</html>
Javascript
function gstCalc(){
    var pn=document.getElementById("pn").value;
    var pp=document.getElementById("pp").value;
    var pr=document.getElementById("rate").value;
    var pq=document.getElementById("pq").value;
    var ps=document.getElementById("ps").value;
    var total=pp*pq;
    if(ps==0){
        var SGST = pr/2;
        var CGST=pr/2;
        var pay=total+(total*SGST/100)+(total*CGST/100);
        document.getElementById("tr1").innerHTML="<td>"+pn+"</td><td>Rs "
        +pp+"</td>"+"</td><td>"
        +pq+"</td>"+"</td><td>Rs "
        +total+"</td>";
        document.getElementById("tr2").innerHTML="<td>SGTS "+SGST+" %</td><td></td>"+"</td><td></td>"+"</td><td>Rs "
        +total*SGST/100+"</td>";
       
        document.getElementById("tr3").innerHTML="<td>CGST "+CGST+" %</td><td></td>"+"</td><td></td>"+"</td><td>Rs "
        +total*CGST/100+"</td>";
        document.getElementById("tr4").innerHTML="<td>Total</td><td></td>"+"</td><td></td>"+"</td><td>Rs "
        +pay+"</td>";
    }else{
        var IGST = pr;
      
        var pay=total+(total*IGST/100);
        document.getElementById("tr1").innerHTML="<td>"+pn+"</td><td>Rs "
        +pp+"</td>"+"</td><td>"
        +pq+"</td>"+"</td><td> Rs"
        +total+"</td>";
       
        document.getElementById("tr2").innerHTML="";
        document.getElementById("tr3").innerHTML="<td>IGST "+IGST+" %</td><td></td>"+"</td><td></td>"+"</td><td>Rs "
        +total*IGST/100+"</td>";
        document.getElementById("tr4").innerHTML="<td>Total</td><td></td>"+"</td><td></td>"+"</td><td>Rs "
        +pay+"</td>";
        
    }
}

Comments

Popular posts from this blog

How to make simple bill maker by using python tkinter

Write a program to find the sum of 1/2+4/3+5/6+8/7+9/10 using loop in java