NetSalary

 

<html>

<head>

<title> Basic Salary </title>

<script type="text/javascript">

function vali()

{

           

             emp=document.getElementById('n1').value;

             nm=document.getElementById('t2').value;

             bs=document.getElementById('t3').value;

 

            //-------------Validation for emp no------------

 

            if(document.getElementById('n1').value =='')

            {

                        alert("You must enter Employee no");

                        return false;

            }

            var e = document.getElementById('n1').value;

            if(isNaN(e)||e.indexOf(" ")!=-1)

           {

              alert("Invalid number");

            

              return false;

           }

           

 

            //-----------validation for name--------------------

 

           

            if(document.getElementById('t2').value =='')

            {

                        alert("You must enter name");

                        return false;

            }         

            if(nm)

            {

                        for(var i=0;i<nm.length;i++)

                        {

                                    if(nm.charAt(i) < 'A' || nm.charAt(i) > 'Z' && nm.charAt(i) <'a' || nm.charAt(i)>'z')

                                    {

                                                            alert("Invalid Text in name field")

                                                            return false;

                                    }

                        }

            }

 

            //--------------Validation for Basic salary------------------

 

            if(document.getElementById('t3').value =='')

            {

                        alert("You must enter basic salary");

                        return false;

            }

            var c = document.getElementById('t3').value;

            if(isNaN(c)||c.indexOf(" ")!=-1)

           {

              alert("Invalid number in basic salary field");

            

              return false;

           }

 

            return true;

            }

 

function calc()

            {

            //----------------Calculate Net Salary--------------

 

            var y=parseInt(document.forma.t3.value)

            var hra=parseInt(y*8/100)

            var da=parseInt(y*5/100)

            var ta=parseInt(y*3/100)

            var ns=parseInt(y+hra+da+ta)

            alert("Net salary:"+ns);

                // document.write("Net salary:"+ns);

 

            }

 

</script>

</head>

 

<body>

<center> Employee Details </center>

<table align="center">

<form action="#" name="forma">

<tr>

<td>

Employee no: </td>

<td> <input type="text" name="n1" id="n1"> </td>

</tr>

<tr>

<td> Name: </td>

<td> <input type="text" name="t2" id="t2"> </td>

</tr>

<tr>

<td> Basic Salary: </td>

<td> <input type="text" name="t3" id="t3"> </td>

</tr>

<tr>

<td colspan="2"> <center> <input type="button" value="Net Salary"

 onclick="return vali();" ondblclick="return calc();"/>

 

</td>

</tr>

 

</form>

</table>

</body>

</html>