Passing PHP Variable A Modal Window

0

Cordial Greeting.

I hope you can help me with what I want to do.

I have a PHP - HTML table

Well, the fact is that, when I click on the pen, I opened a Modal window:

What I want to do, is to pass 1 variable to the Modal window, by clicking on the pencil.

This is the structure of the piece that I need:

<td><?php echo $row['Descr']; ?><a href="#miModal" data-toggle="modal"><img src="img/editar.png" class="btn"></a></td>

and this is the Modal:

<div class="modal fade" id="miModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
        <h4 class="modal-title" id="myModalLabel">Editar Nombre del Concepto</h4>
      </div>
      <div class="modal-body">
        <label>Nombre Concepto:</label>
            <input type="text" name="nombre" id="nombre" required="on" autocomplete="off" class="form-control"><br/>
            <input type="button" name="insert" onclick="actualizarnombrecon();" class="btn btn-primary"  value="GUARDAR">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <button type="button" class="btn btn-warning" data-dismiss="modal">CANCELAR</button>           
      </div>
    </div>
  </div>
</div>

I really do not know how to make it work

I hope you can help me

Thanks in advance

    
asked by Andres Rodriguez 22.11.2018 в 22:43
source

1 answer

2

It seems that you are using some framework, of the Bootstrap style. Normally these frameworks allow you to open the modal window automatically, as I believe you are doing, adding the attributes data-toggle="modal" and href="#miModal" , or open it programmatically, which is what you need.

Depending on the framework you are using, you will have to do something similar to this:

Change the button of the pencil (by removing the link <a> ):

<img src="img/editar.png"
     class="lapiz"
     data-descr="<?php echo htmlentities($row['Descr']); ?>">

Add a code that handles the click on the pen, update the field and show the window:

<script>
    $(document).on('click', '.lapiz', function () {

        var descr = $(this).attr('data-descr');
        $('#miModal input[name=nombre]').val(descr);

        // aquí es cuando tienes que mirar la documentación de tu framework
        $('#miModal').showModal(); // o similar

    });
</script>
    
answered by 22.11.2018 / 22:56
source