
document.addEventListener('DOMContentLoaded', function () {
   
    document.getElementById('myForm').addEventListener('submit', function (event) {
    
        event.preventDefault(); 
       
        let EPFNO = document.getElementById('EPFNO').value;
        let Designation = document.getElementById('Designation').value;
        let Title = document.getElementById('Title').value;
        let empoyeename = document.getElementById('empoyeename').value;
        let Gender = document.getElementById('Gender').value;
        let Basic = document.getElementById('Basic').value;
        let DA = document.getElementById('DA').value;
        let HRA = document.getElementById('HRA').value;
        let WA = document.getElementById('WA').value;
        let CA = document.getElementById('CA').value;
        let CCA = document.getElementById('CCA').value;
        let MA = document.getElementById('MA').value;
        let SalesIncentive = document.getElementById('SalesIncentive').value;
        let leaveencashment = document.getElementById('leaveencashment').value;
        let HolidayWages = document.getElementById('HolidayWages').value;
        let SpecialAllowance = document.getElementById('SpecialAllowance').value;
        let ESI = document.getElementById('ESI').value;
        let PF = document.getElementById('PF').value;
        let Bonus = document.getElementById('Bonus').value;
        let TDS = document.getElementById('TDS').value;
        let LOP = document.getElementById('LOP').value;
        let PT = document.getElementById('PT').value;
        let SPLDeduction = document.getElementById('SPLDeduction').value;
        let EWF = document.getElementById('EWF').value; 
        let Salaryname = document.getElementById('Salaryname').value;
        let NetPay = document.getElementById('NetPay').value;
        
    

        if (EPFNO=="") {
            alert('Please Enter The EPFNO.');
            return;
        }
        else if(Designation =="") {
            alert('Please enter the Designation');
            return;
        }
        else if(Title == "") {
            alert('Please enter the Title');
            return;
        } else if(empoyeename == "") {
            alert('Please enter the empoyeename');
            return;
        }  else if(Gender == "") {
            alert('Please enter the Gender');
            return;
        }  else if(Basic == "") {
            alert('Please enter the Basic');
            return;
        } else if(DA == "") {
            alert('Please enter the DA');
            return;
        } else if(HRA == "") {
            alert('Please enter the HRA');
            return;
        } else if(WA == "") {
            alert('Please enter the WA');
            return;
        } else if(CA == "") {
            alert('Please enter the CA');
            return;
        } else if(CCA == "") {
            alert('Please enter the CCA');
            return;
        } else if(MA == "") {
            alert('Please enter the MA');
            return;
        } else if(SalesIncentive == "") {
            alert('Please enter the SalesIncentive');
            return;
        } else if(leaveencashment == "") {
            alert('Please enter the leaveencashment');
            return;
        } else if(HolidayWages == "") {
            alert('Please enter the HolidayWages');
            return;
        } else if(SpecialAllowance == "") {
            alert('Please enter the SpecialAllowance');
            return;
        } else if(ESI == "") {
            alert('Please enter the ESI');
            return;
        } else if(PF == "") {
            alert('Please enter the PF');
            return;

        } else if(Bonus == "") {
            alert('Please enter the Bonus');
            return;
        } else if(TDS == "") {
            alert('Please enter the TDS');
            return;
        } else if(LOP == "") {
            alert('Please enter the LOP');
            return;
        } else if(PT == "") {
            alert('Please enter the PT');
            return;
        } else if(SPLDeduction == "") {
            alert('Please enter the SPLDeduction');
            return;
        }
        else if(EWF == "") {
            alert('Please enter the EWF');
            return;
        }  else if(Salaryname == "") {
            alert('Please enter the Salaryname');
            return;
        } else if(NetPay == "") {
            alert('Please enter the NetPay');
            return;
        }

        // else {
     
        let formData = new FormData();
        formData.append('EPFNO', EPFNO);
        formData.append('Designation', Designation);
        formData.append('Title', Title);
        formData.append('empoyeename', empoyeename);
        formData.append('Gender', Gender);
        formData.append('Basic', Basic);
        formData.append('DA', DA);
        formData.append('HRA', HRA);
        formData.append('WA', WA);
        formData.append('CA', CA);
        formData.append('CCA', CCA);
        formData.append('MA', MA);
        formData.append('SalesIncentive', SalesIncentive);
        formData.append('leaveencashment', leaveencashment);
        formData.append('HolidayWages', HolidayWages);
        formData.append('SpecialAllowance', SpecialAllowance);
        formData.append('ESI', ESI);
        formData.append('PF', PF);
        formData.append('Bonus', Bonus);
        formData.append('TDS', TDS);
        formData.append('LOP', LOP);
        formData.append('PT', PT);
        formData.append('SPLDeduction', SPLDeduction);
        formData.append('EWF', EWF);
        formData.append('Salaryname', Salaryname);
        formData.append('NetPay', NetPay);
        
     

        let xhr = new XMLHttpRequest();
        xhr.open('POST', 'salarydata.php', true);
        xhr.onload = function () {
            if (xhr.status === 200) {
                 document.getElementById('response').innerHTML = xhr.responseText;
                 location.reload();
                // alert(xhr.responseText);
            } else {
                document.getElementById('response').innerHTML = 'An error occurred.';
            }
        };
        xhr.send(formData);
        location.reload();
       
    
    });
  
   
   
});


// const myButton = document.getElementById('myButton');

// // Assign an onclick function to the button
// myButton.onclick = function() {
//     // alert('test');
//     location.reload(); 
// };
