JezK
Edit File: page4.php
<?php include("header.php"); $_SESSION['bcFormPage'] = "page4.php"; //echo "<pre>";print_r($details);exit; if(!isset($_SESSION['bcFormUserID'])) { echo "<script>location.replace('page1.php');</script>"; } $currentUserID = $_SESSION['bcFormUserID']; if(isset($_SESSION['saveSuccess'])) { echo "<script>alert('Data saved successfully.');</script>"; unset($_SESSION['saveSuccess']); } if(isset($_SESSION['page4SaveFailed'])) { echo "<script>alert('Error!!! Unable to save user details. Internal server error.');</script>"; unset($_SESSION['page4SaveFailed']); } if(isset($_SESSION['staffingSaveFailed'])) { echo "<script>alert('Error!!! Unable to save staff details. Internal server error.');</script>"; unset($_SESSION['staffingSaveFailed']); } if(isset($_SESSION['staffingUpdateFailed'])) { echo "<script>alert('Error!!! Unable to update staff details. Internal server error.');</script>"; unset($_SESSION['staffingUpdateFailed']); } if(isset($_SESSION['otherSaveFailed'])) { echo "<script>alert('Error!!! Unable to save other details. Internal server error.');</script>"; unset($_SESSION['otherSaveFailed']); } if(isset($_SESSION['otherUpdateFailed'])) { echo "<script>alert('Error!!! Unable to update other details. Internal server error.');</script>"; unset($_SESSION['otherUpdateFailed']); } if(isset($_SESSION['deleteSuccess'])) { echo "<script>alert('Data deleted succesfully.');</script>"; unset($_SESSION['deleteSuccess']); } if(isset($_SESSION['deleteFailed'])) { echo "<script>alert('Error!!! Unable to delete registration details. Internal server error.');</script>"; unset($_SESSION['deleteFailed']); } if(isset($_SESSION['structuralFileUploadFailed'])) { echo "<script>alert('Error!!! Unable to upload structural file. Internal server error.');</script>"; unset($_SESSION['structuralFileUploadFailed']); } if(isset($_SESSION['structuralFileSaveFailed'])) { echo "<script>alert('Error!!! Unable to save structural file details. Internal server error.');</script>"; unset($_SESSION['structuralFileSaveFailed']); } ?> <div class="container main"> <div class="row"> <form action = "app/page4App.php" class="form-horizontal" enctype="multipart/form-data" method="post" onsubmit="return validatePage4()"> <div class="col-md-12 col-md-offset-0 formContainer"> <h3>Staffing pattern <span class="star">*</span></h3> <section> <div class="col-md-12 removePadding"> <h3 class="subHead">Please give details of organizational structure/profile</h3> <textarea style="width:100%" name="structuralDetails" id="structuralDetails" rows="7"><?php echo $structuralDetails;; ?></textarea> <!--<h3 class="subHead">Board Resolution-Upload function in management authorize</h3> <div class="form-group"> <label class="col-md-2 labelPadding" >File Upload:<br> <small> (upload pdf only)</small></label> <input type="hidden" value="<?php echo $txtStructuralFileStatus; ?>" id="txtStructuralFileStatus"> <input type="file" name="structuralFile" id="structuralFile" value="" class="browse-o" onchange="ValidateFileUpload('structuralFile','txtStructuralFileStatus')"> <input type="hidden" value="<?php echo $txtStructureStatus; ?>" id="txtStructureUpload"> <button type="button" class="browse-d">Browse</button> <!--<input type="button" value="Upload" class="uploadBtn" onclick="validatePDF(4,'structuralFile')">--> <!-- <div id="staffUploadStatus" class="divSuccess"><?php echo $structuralUploadStatus; ?></div> </div>--> </div> </section> <section> <h3 class="subHead col-md-11 removePadding">Staff Details</h3> <input type="button" class="btn btn-default addBtn1 pull-right col-md-1" value="Add New" > <div class="col-md-12 table-responsive removePadding"> <table class="table table-bordered cs-table table-responsive"> <thead> <tr> <th>Name</th> <th>Designation(Office Staff, Supervisory staff, or Volunteer)</th> <th>Experience in years</th> <th>Date of appointment</th> <th>Action</th> </tr> </thead> <tbody class="input_fields_wrap1"> <?php echo $staffingDetails;; ?> </tbody> </table> </div> </section> <!--<section> <div class=""> <div class="col-md-12 removePadding"> <h3 class="subHead">Financial year staff progress</h3> </div> <div class="col-md-12 removePadding table-responsive"> <table class="table table-bordered cs-table"> <thead> <tr> <th>Year</th> <th>Office Staff(No.)</th> <th>Supervisory Staff(No.)</th> <th>Field Staff(No.)</th> <th>Total Staff(No.)</th> </tr> </thead> <tbody class="input_fields_wrap2"> <tr > <td> <input type='text' value="<?php echo $financialYear; ?>" name="financialYear" id="financialYear" placeholder="Year" maxlength="4" onkeypress="return number(event)"> </td> <td> <input type='text' name="officeStaff" id="officeStaff" value="<?php echo $officeStaff; ?>" placeholder="Office Staff(No.)" onkeypress="return number(event)"> </td> <td> <input type="text" name="supervisoryStaff" id="supervisoryStaff" value="<?php echo $supervisoryStaff; ?>" placeholder="Supervisory Staff(No.)" onkeypress="return number(event)"> </td> <td> <input type="text" name="fieldStaff" id="fieldStaff" value="<?php echo $fieldStaff; ?>" placeholder="Field Staff(No.)" onkeypress="return number(event)"> </td> <td> <input type="text" name="totalStaff" id="totalStaff" value="<?php echo $usersTotalStaff; ?>" placeholder="Total Staff(No.)" onkeypress="return number(event)"> </td> </tr> </tbody> </table> </div> </div> </section>--> <section> <div class=""> <div class="col-md-12 removePadding"> <h3 class="subHead">Financial year staff progress</h3> </div> <div class="col-md-12 removePadding table-responsive"> <table class="table table-bordered cs-table"> <thead> <tr> <th>S. No</th> <th>Total Staff (No.) [A]</th> <th>Staff Left during this year [B]</th> <!--<th>Attribution Rate B/A %</th>--> <th>Attrition Rate B/A %</th> </tr> </thead> <tbody class="input_fields_wrap2"> <tr> <td><input type='text' value="<?php echo $financialYear3; ?>" name="financialYear1" id="financialYear1" placeholder="Year" onkeypress="return number3(event)" maxlength="10" ></td> <td> <input type='text' name="totalStaff1" id="totalStaff1" value="<?php echo $totalStaff3; ?>" placeholder="Enter number only" onkeypress="return number(event)" onblur="calculateAttributionRate(1)"> </td> <td> <input type="text" name="staffLeft1" id="staffLeft1" value="<?php echo $staffLeft3; ?>" placeholder="Enter number only" onkeypress="return number(event)" onblur="calculateAttributionRate(1)"> </td> <td> <input type="text" name="attributionRate1" id="attributionRate1" value="<?php echo $attributionRate3; ?>" placeholder="" readonly> </td> </tr> <tr> <td><input type='text' value="<?php echo $financialYear2; ?>" name="financialYear2" id="financialYear2" placeholder="Year" maxlength="10" onkeypress="return number3(event)"></td> <td> <input type='text' name="totalStaff2" id="totalStaff2" value="<?php echo $totalStaff2; ?>" placeholder="Enter number only" onkeypress="return number(event)" onblur="calculateAttributionRate(2)"> </td> <td> <input type="text" name="staffLeft2" id="staffLeft2" value="<?php echo $staffLeft2; ?>" placeholder="Enter number only" onkeypress="return number(event)" onblur="calculateAttributionRate(2)"> </td> <td> <input type="text" name="attributionRate2" id="attributionRate2" value="<?php echo $attributionRate3; ?>" placeholder="" readonly> </td> </tr> <tr> <td><input type='text' value="<?php echo $financialYear1; ?>" name="financialYear3" id="financialYear3" placeholder="Year" maxlength="10" onkeypress="return number3(event)" ></td> <td> <input type='text' name="totalStaff3" id="totalStaff3" value="<?php echo $totalStaff1; ?>" placeholder="Enter number only" onkeypress="return number(event)" onblur="calculateAttributionRate(3)"> </td> <td> <input type="text" name="staffLeft3" id="staffLeft3" value="<?php echo $staffLeft1; ?>" placeholder="Enter number only" onkeypress="return number(event)" onblur="calculateAttributionRate(3)"> </td> <td> <input type="text" name="attributionRate3" id="attributionRate3" value="<?php echo $attributionRate1; ?>" placeholder="" readonly> </td> </tr> </tbody> </table> </div> </div> </section> <section> <div class="col-md-12 removePadding"> <h3 class="subHead">Details of infrastructure available for the activity: <span class="star">*</span></h3> </div> <div class="table-responsive col-md-12 removePadding"> <table class="table table-bordered cs-table table-responsive"> <thead> <tr> <th>Type of Infrastructure</th> <th>Description</th> <th>Remarks</th> </tr> </thead> <tbody class="input_fields_wrap3"> <tr> <td> Head Office Address </td> <td> <textarea type='text' name="headOfficeDescription" id="headOfficeDescription" placeholder=""><?php echo $headOfficeDescription; ?></textarea> </td> <td> <textarea type='text' name="headOfficeRemarks" id="headOfficeRemarks" placeholder=""><?php echo $headOfficeRemarks; ?></textarea> </td> </tr> <tr> <td> Number of field officers </td> <td> <textarea type='text' name="fieldOfficeDescription" id="fieldOfficeDescription" placeholder=""><?php echo $fieldOfficeDescription; ?></textarea> </td> <td> <textarea type='text' name="fieldOfficeRemarks" id="fieldOfficeRemarks" placeholder=""><?php echo $fieldOfficeRemarks; ?></textarea> </td> </tr> <tr> <td> Training Center </td> <td> <textarea type='text' name="trainingCenterDescription" id="trainingCenterDescription" placeholder=""><?php echo $trainingCenterDescription; ?></textarea> </td> <td> <textarea type='text' name="trainingCenterRemarks" id="trainingCenterRemarks" placeholder=""><?php echo $trainingCenterRemarks; ?></textarea> </td> </tr> <!-- <tr> <td> Number of Staff </td> <td> <input type='text' name="numberOfStaff" id="numberOfStaff" value="<?php echo $numberOfStaff; ?>" placeholder="Enter number only" onkeypress="return number(event)"> </td> <td> <textarea type='text' name="staffRemarks" id="staffRemarks" placeholder=""><?php echo $staffRemarks; ?></textarea> </td> </tr>--> <tr> <td> How many of them have own vehicles </td> <td> <input type="text" name="vehiclesOwned" id="vehiclesOwned" value="<?php echo $vehiclesOwned; ?>" placeholder="Enter number only" onkeypress="return number(event)"> </td> <td> <textarea type='text' name="vehiclesRemarks" id="vehiclesRemarks" placeholder=""><?php echo $vehiclesRemarks; ?></textarea> </td> </tr> <tr> <td> Office Purpose Computers / Laptops </td> <td> <input type="text" name="totalComputers" id="totalComputers" value="<?php echo $totalComputers; ?>" placeholder="Enter number only" onkeypress="return number(event)"> </td> <td> <textarea type='text' name="computersRemarks" id="computersRemarks" placeholder=""><?php echo $computersRemarks; ?></textarea> <input type="button" value="Any other" class="btn btn-default newField pull-right" > </td> <?php echo $otherDetailsView; ?> </tr> </tbody> </table> </div> </section> <div class="text-center col-md-12"> <a href="page3.php"><input type="button" value="Back" class="btn btn-cs"></a> <input type="submit" value="Next" class="btn btn-cs"> </div> <div class="col-md-12 text-right">4 of 6</div> </div><!--end formContainer--> </form> </div> </div> </div> <?php echo include"footer.php"?> <script type='text/javascript'> pdfFlag = 0; $(document).ready(function() { $(".browse-d").click(function(){ $(this).parents(".form-group").find('.browse-o').click(); //$(".browse-o").closest(".form-group"); }); //var max_fields = ; //maximum input boxes allowed var wrapper1 = $(".input_fields_wrap1"); //Fields wrapper var add_button1 = $(".addBtn1"); //Add button ID var x = '<?php echo $staffingDetailsCount; ?>' ; //initlal text box count // var x = 2 ; //initlal text box count $(add_button1).click(function(e) { /*staffName = document.getElementById('name'+x); designation = document.getElementById('designation'+x); experience = document.getElementById('experience'+x); appointmentDate = document.getElementById('appointmentDate'+x);*/ staffNameLength = document.getElementsByName('name[]').length; for(i=0;i<staffNameLength;i++) { staffName = document.getElementsByName('name[]'); designation = document.getElementsByName('designation[]'); experience = document.getElementsByName('experience[]'); appointmentDate = document.getElementsByName('appointmentDate[]'); if(staffName[i].value.trim() != "" && designation[i].value.trim() != "" && experience[i].value.trim() != "" && appointmentDate[i].value.trim() != "" ) { flag1 = 1; } else { flag1 = 0; break; } } if(flag1 == 1) { //on add input button click e.preventDefault(); // if(x < max_fields){ //max input box allowed x++; //text box increment // <input type="text" name="designation[]" id="designation'+x+'" placeholder=" Name"> $(wrapper1).append('<tr ><td><input type="hidden" name="staffID[]" id="staffID'+x+'" value=""><input type="text" name="name[]" id="name'+x+'" placeholder=" Name"></td><td>\ <select name="designation[]" id="designation'+x+'" > \ <option value="Office Staff" >Office Staff</option> \ <option value="Field Staff" >Field Staff</option>\ <option value="Supervisory staff" >Supervisory staff</option> \ <option value="Volunteer" >Volunteer</option> \ </select> \ </td><td><input type="text" name="experience[]" id="experience'+x+'" placeholder="Experience"></td><td><div class="input-group date col-md-3" ><input type="text" class="form-control" name="appointmentDate[]" id="appointmentDate'+x+'" placeholder="Date of appointment" readonly /><span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span></div></td><td><a class="action2"><i class="fa fa-trash remove_field1" aria-hidden="true" ></i></a></td></tr>'); //add input box //} $('.input-group.date').datepicker({ calendarWeeks: true, todayHighlight: true, autoclose: true, format:"dd/mm/yyyy" }); } else { alert("Please fill all fields first."); } }); $(wrapper1).on("click",".remove_field1", function(e){ //user click on remove text e.preventDefault(); $(this).closest('tr').remove(); }); var wrapper2 = $(".input_fields_wrap2"); var add_button2 = $(".addBtn2"); var x = 1; $(add_button2).click(function(e){ e.preventDefault(); // if(x < max_fields){ //max input box allowed x++; //text box increment $(wrapper2).append('<tr ><td><input type="text" name="year[]" placeholder=" Year"></td><td><input type="text" name="boardMettings[]" placeholder="No. of Board meeting held" /></td><td><input type="text" name="avgAttendance[]" placeholder="Average Attendance"></td><td><a class="action2"><i class="fa fa-trash remove_field2" aria-hidden="true" ></i></a></td></tr>'); //add input box //} }); $(wrapper2).on("click",".remove_field2", function(e){ //user click on remove text e.preventDefault(); $(this).closest('tr').remove(); }) //var max_fields = ; //maximum input boxes allowed var wrapper3 = $(".input_fields_wrap3"); //Fields wrapper var add_button3 = $(".addBtn3"); //Add button ID $('.input-group.date').datepicker({ calendarWeeks: true, todayHighlight: true, autoclose: true, format:"dd/mm/yyyy" }); var x = 1; //initlal text box count $(add_button3).click(function(e){ //on add input button click e.preventDefault(); // if(x < max_fields){ //max input box allowed x++; //text box increment $(wrapper3).append('<tr><td><input type="text" name="name[]" placeholder=" Name"></td><td><select><option>Select Designation</option><option>member</option></select></td><td><input type="text" name="qualification[]" placeholder="Qualification"></td><td><input type="text" name="experience[]" placeholder="Experience "></td><td><div class="input-group date"><input type="text" class="form-control" name="dateOfAppointment[]" placeholder="Date of appointment" readonly /><span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span></div></td><td class="td4"><textarea name="associationDetails[]" placeholder="Details of association with any other institution" /></textarea></td><td><input type="file" value="" class="browse-o"><button type="button" class="browse-d">Browse</button></td><td><a class="action2"><i class="fa fa-trash remove_field3" aria-hidden="true" ></i></a></td></tr>'); //add input box //} $('.input-group.date').datepicker({ calendarWeeks: true, todayHighlight: true, autoclose: true, format:"dd/mm/yyyy" }); }); $(wrapper3).on("click",".remove_field3", function(e){ //user click on remove text e.preventDefault(); $(this).closest('tr').remove(); }); /* //var max_fields = ; //maximum input boxes allowed var newBlock = $(".input_fields_wrap3"); //Fields wrapper var newField = $(".newField"); //Add button ID var otherName = '<?php echo $otherName; ?>'; if(otherName != '') { $(newField).hide(); $(newBlock).append('<tr><td> \ <input type="text" name="otherName" id="otherName" value="<?php echo $otherName; ?>" placeholder="Any other" > \ </td> \ <td> \ <textarea name="otherDescription" id="otherDescription" placeholder=""><?php echo $otherDescription; ?></textarea> \ </td> \ \<td><textarea type="text" name="otherRemarks" id="otherRemarks" placeholder=""><?php echo $otherRemarks; ?></textarea><a href="app/deleteFieldsApp.php?id=<?php echo $currentUserID; ?>" class="action2" onclick=\'return confirm("Are you sure you want to delete?")\'><i class="fa fa-trash" aria-hidden="true" ></i></a></td></tr>'); } var x31 = 1; //initlal text box count $(newField).click(function(e) { //on add input button click e.preventDefault(); if(x31 <= 1){ //max input box allowed x31++; //text box increment $(newField).hide(); $(newBlock).append('<tr><td> \ <input type="text" name="otherName" id="otherName" value="<?php echo $otherName; ?>" placeholder="Any other" > \ </td> \ <td> \ <textarea name="otherDescription" id="otherDescription" placeholder=""><?php echo $otherDescription; ?></textarea> \ </td> \ <td> \ <textarea type="text" name="otherRemarks" id="otherRemarks" placeholder=""><?php echo $otherRemarks; ?></textarea> \ <a class="action2 pull-right" onclick="clearOtherData()"><i class="fa fa-trash removeBlock" aria-hidden="true" ></i></a> \ </td></tr>'); //add input box //} } }); $(newBlock).on("click",".removeBlock", function(e){ //user click on remove text e.preventDefault(); $(this).closest('tr').remove();x31--; $(newField).show(); //$input_fields_wrap3 });*/ }); function clearOtherData() { document.getElementById('otherName').value=""; document.getElementById('otherDescription').value=""; document.getElementById('otherRemarks').value=""; } function ValidateFileUpload(fileID,txtID) { pdfFlag = 0; var fuData = document.getElementById(fileID); var txtField = document.getElementById(txtID); var txtField2 = document.getElementById('txtStructureUpload'); var staffUploadStatus = document.getElementById('staffUploadStatus'); var FileUploadPath = fuData.value; //To check if user upload any file if (FileUploadPath == '') { alert("Please upload a pdf file."); txtField.value = 0; txtField2.value = 0; pdfFlag = 0; } else { var Extension = FileUploadPath.substring( FileUploadPath.lastIndexOf('.') + 1).toLowerCase(); //The file uploaded is an pdf if (Extension == "pdf") { var size=1048576; var file_size=fuData.files[0].size; if(file_size>=size) { alert('File too large'); staffUploadStatus.innerHTML = '<span class="fail"></span>'; pdfFlag = 0; txtField.value = 0; txtField2.value = 0; } else { pdfFlag = 1; txtField.value = 1; txtField2.value = 1; } } //The file upload is NOT an pdf else { alert("Please upload a pdf file."); txtField.value = 0; txtField2.value = 0; pdfFlag = 0; staffUploadStatus.innerHTML = '<span class="fail"></span>'; } } } function validatePDF(type,fileID) { if(pdfFlag == 0) { alert('Please upload a valid file'); } else { var fuData = document.getElementById(fileID); var txtStructureUpload = document.getElementById('txtStructureUpload'); var staffUploadStatus = document.getElementById('staffUploadStatus'); var fd = new FormData(); fd.append('userFile',$('#'+fileID)[0].files[0]); fd.append('type',type); $.ajax({ url: 'app/ajax.php', data: fd, processData: false, contentType: false, type: 'POST', success: function(data) { if(data == -4) { alert('Unable to upload deeds declarion file.'); staffUploadStatus.innerHTML = '<span class="fail"></span>'; } else if(data == -3) { alert('Error!!! Unable to save deed details. Internal server error.'); staffUploadStatus.innerHTML = '<span class="fail"></span>'; } else { alert('Data saved successfully.'); staffUploadStatus.innerHTML = '<span class="success"></span>'; txtStructureUpload.value = 1; //location.reload(); } } }); } } function number3(e) { var key = e.keyCode || e.charCode; if(key == 13 || key == 43 || (key >= 48 && key <= 57) || key == 8 || key == 46 || key==45) { return true; } else { return false; } } function number(e) { //if(e.keyCode == 13 || (e.keyCode >= 48 && e.keyCode <= 57)) var key = e.keyCode || e.charCode; if(key == 13 || key == 43 || (key >= 48 && key <= 57) || key == 8 || key == 46) { return true; } else { return false; } } function validatePage4() { staffName = document.getElementById('name1'); designation = document.getElementById('designation1'); experience = document.getElementById('experience1'); appointmentDate = document.getElementById('appointmentDate1'); /*txtStructureUpload = document.getElementById('txtStructureUpload'); txtStructuralFileStatus = document.getElementById('txtStructuralFileStatus');*/ headOfficeDescription = document.getElementById('headOfficeDescription'); headOfficeRemarks = document.getElementById('headOfficeRemarks'); fieldOfficeDescription = document.getElementById('fieldOfficeDescription'); fieldOfficeRemarks = document.getElementById('fieldOfficeRemarks'); trainingCenterDescription = document.getElementById('trainingCenterDescription'); trainingCenterRemarks = document.getElementById('trainingCenterRemarks'); numberOfStaff = document.getElementById('numberOfStaff'); staffRemarks = document.getElementById('staffRemarks'); vehiclesOwned = document.getElementById('vehiclesOwned'); vehiclesRemarks = document.getElementById('vehiclesRemarks'); totalComputers = document.getElementById('totalComputers'); computersRemarks = document.getElementById('computersRemarks'); /*if(txtStructureUpload.value == 0) { alert('Plese upload a valid file.'); return false; } if(txtStructuralFileStatus.value == 0) { alert('Plese upload a valid file.'); return false; }*/ if(staffName.value.trim() == 0) { alert('Plese enter staff name.'); staffName.focus(); return false; } if(designation.value.trim() == 0) { alert('Plese enter designation.'); designation.focus(); return false; } if(experience.value.trim() == "") { alert('Plese enter experience.'); experience.focus(); return false; } if(appointmentDate.value.trim() == 0) { alert('Plese enter appointment date.'); appointmentDate.focus(); return false; } if(headOfficeDescription.value.trim() == 0) { alert('Plese enter headOffice description.'); headOfficeDescription.focus(); return false; } /*if(headOfficeRemarks.value.trim() == 0) { alert('Plese enter headOffice remarks.'); headOfficeRemarks.focus(); return false; }*/ if(fieldOfficeDescription.value.trim() == 0) { alert('Plese enter field office description.'); fieldOfficeDescription.focus(); return false; } if(trainingCenterDescription.value.trim() == 0) { alert('Plese enter training center description.'); trainingCenterDescription.focus(); return false; } /*if(numberOfStaff.value.trim() == 0) { alert('Plese enter total staff.'); numberOfStaff.focus(); return false; }*/ if(vehiclesOwned.value.trim() == 0) { alert('Plese enter vehicles owned.'); vehiclesOwned.focus(); return false; } if(totalComputers.value.trim() == 0) { alert('Plese enter total computers.'); totalComputers.focus(); return false; } otherNameLength = document.getElementsByName('otherName[]').length; //alert(otherNameLength); if(otherNameLength>0) { for(i=0;i<otherNameLength;i++) { otherName = document.getElementsByName('otherName[]'); otherDescription = document.getElementsByName('otherDescription[]'); if(otherName[i].value.trim() == "" ) { alert('Plese enter other name.'); otherName[i].focus(); return false; } if(otherDescription[i].value.trim() == "" ) { alert('Plese enter other description.'); otherDescription[i].focus(); return false; } } } return true; } function calculateAttributionRate(i) { var totalStaff = parseInt(document.getElementById('totalStaff'+i).value); var staffLeft = parseInt(document.getElementById('staffLeft'+i).value); if(totalStaff != "" && staffLeft != "") { if(totalStaff != 0) { attributionRate = (staffLeft/totalStaff).toFixed(2); if(isNaN(attributionRate)) { attributionRate = ""; } else { attributionRate += ' %'; } } else { attributionRate = ""; } } document.getElementById('attributionRate'+i).value = attributionRate; } //Any othe field adding $(document).ready(function() { var max_fields = 5 ; //maximum input boxes allowed var wrapper = $(".input_fields_wrap3"); //Fields wrapper var add_button = $(".newField"); //Add button ID var other = '<?php echo $otherDetailsCount; ?>'; //initlal text box count $(add_button).click(function(e) { //alert(other); if(other == 4) { $(".newField").css("display","none"); } //on add input button click e.preventDefault(); if(other < max_fields) { //max input box allowed $(wrapper).append('<tr><td> \ <input type="hidden" name="otherID[]" value="">\ <input type="text" name="otherName[]" id="otherName" value="" placeholder="Any other" > \ </td> \ <td> \ <textarea name="otherDescription[]" id="otherDescription" placeholder=""></textarea> \ </td> \ <td> \ <textarea type="text" name="otherRemarks[]" id="otherRemarks" placeholder=""></textarea> \ <a class="action2 pull-right" ><i class="fa fa-trash removeBlock" aria-hidden="true" ></i></a> \ </td></tr>'); //add input box } other++; //text box increment }); $(wrapper).on("click",".removeBlock", function(e){ //alert(other); //user click on remove text if(other <= 5) { $(".newField").css("display","block"); } e.preventDefault(); $(this).closest('tr').remove();other--; }); }); </script>