I've been working on an edit/update button that will toggle a modal that looks like this:
Is there a better code for this JavaScript code that I made?
<script>
$('body').on('click', '.editButton',function(){
let edit = $(this).val()
console.log("Edit this : " + edit);
$('#updateEmpModal').modal('toggle');
$.ajax({
type : 'POST',
url : 'get.php',
data : {'edit' : edit},
dataType: 'json',
success: function(data){
$("#updateEmpForm input[name='EMAIL']") .val(data.EMAIL);
$("#updateEmpForm input[name='PASSWORD']") .val(data.PASSWORD);
$("#updateEmpForm input[name='RIGHTS']") .val(data.RIGHTS);
$("#updateEmpForm input[name='LAST_NAME']") .val(data.LAST_NAME);
$("#updateEmpForm input[name='FIRST_NAME']") .val(data.FIRST_NAME);
$("#updateEmpForm input[name='MIDDLE_NAME']") .val(data.MIDDLE_NAME);
$("#updateEmpForm input[name='SUFFIX']") .val(data.SUFFIX);
$("#updateEmpForm input[name='GENDER']") .val(data.GENDER);
$("#updateEmpForm input[name='BIRTHDATE']") .val(data.BIRTHDATE);
$("#updateEmpForm input[name='BIRTHPLACE']") .val(data.BIRTHPLACE);
$("#updateEmpForm input[name='CITIZENSHIP']") .val(data.CITIZENSHIP);
$("#updateEmpForm input[name='RELIGION']") .val(data.RELIGION);
$("#updateEmpForm input[name='ADDRESS']") .val(data.ADDRESS);
$("#updateEmpForm input[name='CONTACT']") .val(data.CONTACT);
$("#updateEmpForm input[name='ICE_NAME']") .val(data.ICE_NAME);
$("#updateEmpForm input[name='ICE_CONTACT']") .val(data.ICE_CONTACT);
$("#updateEmpForm input[name='DEPARTMENT']") .val(data.DEPARTMENT);
$("#updateEmpForm input[name='POSITION']") .val(data.POSITION);
$("#updateEmpForm input[name='EMP_TYPE']") .val(data.EMP_TYPE);
$("#updateEmpForm input[name='edit']") .val(data.ID);
}
});
});
</script>
It is working, but I want to know if this is a bad practice and if there are better solutions.
