<!DOCTYPE html>
<html>
<head>
    <title>Table Dynamic Add Or Remove Element</title>
        <link href="https://fonts.googleapis.com/css?family=Raleway" rel="stylesheet">
        <style type="text/css">
        body
        {
            font-family: 'Raleway', sans-serif;
        }
        .wrap
        {
            width:100%;
        }
        input
        {
            margin: 10px;
            outline: none;
            margin-bottom: 10px;
            font-family: 'Raleway', sans-serif;
            border-radius: 2px;
    }
    .textInfo
    {
        margin-bottom: 10px;
        padding: 10px 100px 10px 5px;
        border-radius: 2px;
    }
    #btn{
        padding: 10px 35px;
        outline: none;
        font-family: 'Raleway', sans-serif;
        border:2px solid transparent;
        background: #8BC34A;
        border-radius: 2px;
        color: rgb(255, 255, 255);
        font-weight: normal;
        font-size: 15px;
    }
    #btn:hover{
        background: #fff;
        color:black;
        font-weight: normal;
        font-size: 15px;
        border:2px solid black;
    }
    table td input
    {
        border:none;
        text-align: center;
        border-radius: 2px;
    }
    .container
    {
        width: 80%;
        margin: 0px auto;
    }
    table
    {
        width: 100%;
    }
    table th
    {
        background: #000;
        color:white;
        padding: 5px;
        font-weight: normal;
    }
    #center
    {
        text-align: center;
    }
    table,td,th
    {
        border-collapse: collapse;
        border: 1px solid black;
    }
    #btn1{
        background: rgba(160, 154, 152, 0.58);
        font-family: 'Raleway', sans-serif;
    }
    h1
    {
        font-weight: normal;
        text-align: center;
        color: #8BC34A;
    }
    .messageError
    {
        padding-left: 20px;
        font-size: 11px;
        color:red;
    }
    </style>
</head>
<body>
    <div class="wrap">
        <div class="container">
            <h1>Employee Registration</h1>
            <input class="textInfo" type="text" name="ename" id="name" placeholder="Enter Name" id="name" onblur="validate(this,'Required Field')">
            <span class="messageError"></span>
        </div>
    <div class="container">
        <input class="textInfo"  type="text" name="eadd" id="add" placeholder="Enter Address" id="add" onblur="validate(this,'Required Field')">
            <span class="messageError"></span>
    </div>
    <div class="container">
        <input class="textInfo"  type="text" name="esalary" id="sal" placeholder="Enter Salary" id="sal" onblur="validate(this,'Required Field')"><span class="messageError"></span>
    </div>
    <div class="container">
        <input id="btn" type="submit" name="addBtn" value="Save" onclick="addMoreRows()">
        <table id="tbl_id" style="text-align:center" align="center" valign="top">
        <thead>
                <tr>
                    <th>E_Id</th>
                    <th>Name</th>
                    <th>Address</th>
                    <th>Salary</th>
                    <th>Total</th>
                    <th>Delete</th>
                </tr>
        </thead>
        <tbody>
        </tbody>
</table>    
    </div>
</div>
<script type="text/javascript">
    var calculate=0;
    var count=1;
    var name1=document.getElementById("name");
    var add1=document.getElementById("add");
    var total=document.getElementById("total");
    var sal1=document.getElementById("sal");
    valid=true;
    function validate(el,msg,f){
        field=el;
        v=field.value;
        //var msgError=document.getElementsByClassName("msgError");
        var err=field.parentNode.getElementsByClassName('messageError')[0];
            if(v=="")
            {
                err.innerHTML=msg;
                err.style.display="block";
                valid=false;
            }
            else
            {
                err.style.display="none";
            }
    }       
                inp2.value = sal.value;
                var inp2 = new_row.cells[4].getElementsByTagName('input')[0];
                inp2.id += len;
                inp2.value = calculate+parseInt(sal.value);
                console.log(inp2.value);
                table.appendChild( new_row );
            calculate=calculate+parseInt(sal.value);
            console.log(calculate);
    */
     function addMoreRows(text)
     {
        if(!validate(name1,'Required Field ',true))
        {
            valid=false;
        }
        if(!validate(add1,'Required Field',true))
        {
            valid=false;
        }
        if(!validate(sal1,'Required Field',true))
        {
            valid=false;
        }
        var table = document.getElementById('tbl_id');
        var row = table.insertRow();//create Table Row In 
        var id=row.insertCell(0);
        var name = row.insertCell(1);
        var add = row.insertCell(2);
        var salary = row.insertCell(3);
        var total = row.insertCell(4);
        var del=row.insertCell(5);   
        id.innerHTML=count;
        count=parseInt(count)+1;
        name.innerHTML = name1.value;
        add.innerHTML = add1.value;
        salary.innerHTML = sal1.value;
        total.innerHTML = calculate+parseInt(sal1.value);
        del.innerHTML="<input type='submit' name='btn' id='btn1' value='Delete Record' onclick='deleteRow(this)'>";//button For Perform Delete Operation
         var salary1=parseInt(salary.innerHTML);
         calculate=parseInt(calculate+salary1);
   }
    function deleteRow(row)
    {
            var i=row.parentNode.parentNode.rowIndex;
            console.log(i);
            count=count-1;
            document.getElementById('tbl_id').deleteRow(i);
    }
</script>
</body>
</html>