1
I have this function with the argument '.edit_data
':
$(document).on('click', '.edit_data', function(){
var employee_id = $(this).attr("Id");
$.ajax({
url:"./fetch16",
method:"POST",
data:{employee_id:employee_id},
dataType:"json",
success:function(data){
$('#data11').val(data.data);
$('#Dia11').val(data.Dia);
$('#Fim11').val(data.Fim);
$('#Inicio11').val(data.Inicio);
$('#Colaborador11').val(data.Colaborador);
$('#employee_id').val(data.Id);
$('#insert').val("Gravar");
$('#exampleModal').modal('show');
}
});
});
And I have this function with the argument '.edit_data1'
:
$(document).on('click', '.edit_data1', function(){
var employee_id1 = $(this).attr("Id");
$.ajax({
url:"./fetch16",
method:"POST",
data:{employee_id1:employee_id1},
dataType:"json",
success:function(data){
$('#data12').val(data.data);
$('#Dia12').val(data.Dia);
$('#Fim12').val(data.Fim);
$('#Inicio12').val(data.Inicio);
$('#Colaborador12').val(data.Colaborador);
$('#employee_id1').val(data.Id);
$('#insert1').val("Gravar");
$('#exampleModal1').modal('show');
}
});
});
I wanted to create a single function with both arguments.
<div id="dataModal" class="modal fade" style="margin-top: 12em">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Quarta e Sexta (9H - 12H)</h4>
</div>
<div class="modal-body" id="employee_detail">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Sair</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true" style="margin-top: 12em">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel"><strong>Quarta e Sexta (9H - 12H)</strong></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form method="post" id="insert_form">
<div class="col-md-4 col-xs-4">
<div class="form-group">
<h6><label for="Data Limpeza-name" class="col-form-label">Data Limpeza</label></h6>
<h6><input type="date" name="data" id="data" value="<?php echo date(" Y-m-d ");?>" readonly="true"></h6>
</div>
</div>
<div class="col-md-4 col-xs-4">
<div class="form-group">
<h6><label for="Dia-name" class="col-form-label">Dia Semana</label></h6>
<h6><input type="text" name="Dia" id="Dia" value="<?php echo $dia?>" readonly="true"></h6>
</div>
</div>
<div class="row">
</div>
<div class="col-md-2 col-xs-2">
<div class="form-group">
<h6><label for="Inicio-name" class="col-form-label">Inicio</label></h6>
<h6><input type="time" name="Inicio" id="Inicio" value="09:00" readonly="true"></h6>
</div>
</div>
<div class="col-md-2 col-xs-2">
<div class="form-group">
<h6><label for="Fim-name" class="col-form-label">Fim</label></h6>
<h6><input type="time" name="Fim" id="Fim" value="12:00" readonly="true"></h6>
</div>
</div>
<div class="row">
</div>
<div class="col-md-4 col-xs-4">
<div class="form-group">
<h6><label for="Colaborador-text" class="col-form-label">Colaborador</label></h6>
<h6>
<select style="width:150px" name="Colaborador" id="Colaborador" required>
<option></option>
<?php
$sql = "SELECT Funcionario FROM centrodb.InfoLuvas WHERE Ativo = '1' AND Funcao = 'Limpeza' AND Valencia = 'LAR'";
$qr = mysqli_query($conn, $sql);
while($ln = mysqli_fetch_assoc($qr)){
echo '<option value="'.$ln['Funcionario'].'">'.$ln['Funcionario'].'</option>';
}
?>
</select>
</h6>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Sair</button>
<input type="hidden" name="employee_id" id="employee_id" />
<input type="submit" name="insert" id="insert" value="Registo" data-toggle="modal" class="btn btn-success" />
</div>
</form>
</div>
</div>
</div>
</div>
Why not define a function just for sending data? And then do
$meuelmento.on( "click", function(){ enviaDados(tipo_edit) });
– lazyFox