Print on a href inside a modal the Id of a BD

0

How can I do the following:

I am sending the data from a tr to a modal in the following way:

<span id="Id<?php echo $res['id']; ?>" style="display: none;"><?php echo $res['id']; ?></span>

I pick them up in the modal in the following way:

     <script>
        $(document).ready(function(){
            $(document).on('click', '.edit2', function(){
                var id=$(this).val();
                var Id=$('#Id'+id).text();
                var Name=$('#Name'+id).text();
                var Cargo=$('#Cargo'+id).text();
                var Telefono=$('#Telefono'+id).text();
                var Email=$('#Email'+id).text();


                $('#edit2').modal('show');
                $('#eId').val(Id);
                $('#eName').val(Name);
                $('#eCargo').val(Cargo);
                $('#eTelefono').val(Telefono);
                $('#eEmail').val(Email);

                 });
             });
    </script>

And I printed them in the input in this way:

<input type="text" class="form-control inputmiocont corpiii" id="eId" name="eId">

But I need to print the value the eId on the id tag of this href:

<a href="javascript:void(0);" class="borrar_dato2" id="*Necesito traerlo aqui en PHP" style="text-decoration: none;  font-size: 14px;">
  <i class="icon-trash faboto">Eliminar Contacto</i>
</a>

Ajax to remove:

<script>
$(function()
{
  $(".borrar_dato2").click(function()
  {
   var id = $(this).attr("id");
    var informacion = 'id=' + id;
    if(confirm("¿Seguro que deseas eliminar?"))
  {
    $.ajax({
    type: "POST",
    url: "clientes/delete-contacto.php",
    data: informacion,
    success: function(){}
    });
    $(this).parents(".dato_tabla").animate({ backgroundColor: "#fbc7c7" }, "fast")
    .animate({ opacity: "hide" }, "slow");
    toastr["error"]("Contacto eliminado", "Mensaje")
  }
 return false;
 });
});
</script>
    
asked by Miguel 17.08.2018 в 19:19
source

1 answer

1

You can change the id with $('#eId').attr("id", "nuevoId"); , example:

var Id = "algunNuevoId";

$('#eId').attr("id", Id);

console.log($("#algunNuevoId").text())
Puedes cambiar el id con '$('#eId').attr("id", "nuevoId");', ejemplo:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="eId">modal</div>
    
answered by 17.08.2018 в 19:58