Search value from an input button without reloading page

-1

I load a table with records from an Oracle query. In each row I place 1 button, when I press it I need to call a PHP function that brings me the content in modal form or in a div to the front (it is only text), and that has a button to close it. The function makes a query for the NUMERO_SOCIO field, which I already have available. I do not know how to link the value of NUMERO_SOCIO with each row of the table and how to use the Onclick event to make the query and show it. Help ? The linked code:

while ($fila = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
    $vsocio=trim($fila['NUM_SOCIO']);
    $vfecha=trim($fila['FECHA_HORA']);
    $vapellido=trim($fila['APELLIDO']);
    $vnombre=trim($fila['NOMBRE']);
            
    echo "<tr>\n";
    echo "    <td align='center'>" . $vsocio . "</td>\n";
    echo "    <td align='right'>" . $vfecha . "</td>\n";
    echo "    <td align='left'>" . substr($vnombre . ", " . $vapellido,0,30) . "</td>\n";
    echo "    <td align='center'><input type='button' value='Ver' onClick=''></td>\n";
    echo "</tr>\n";
}
    
asked by look68 02.08.2018 в 20:41
source

2 answers

1

As Victoria Ruiz says. the onClick event would have to receive the member number as a parameter, and then open the modal. For all this you would need to work with JavaScript instead of PHP, since you do not want to reload the page.

If that's what you need, you should just add the Function OnClientClick="return check ();" and add this tag before this JavaScript tag:

<script type="text/javascript">
 funtion comprueba(){
return confirm("Confirme el Postback");
}
</script>

that event is from the client and when you return false you avoid the postback but you could not use the event on the OnClick server if you do not accept it. I hope you serve Greetings

    
answered by 02.08.2018 в 21:13
1

If you just want to see the row in a modal, I would add a class to the button and listen for the click event. Then, I would grab the content of the row and unseat it in the modal. Something like this:

$(".ver").on("click", function() {
  var tds = $(this).parent().siblings();
  var content = "";
  $.each(tds, function(i, td) {
    content += $(td).text() + "<br>";
  });
  
  $("#myModal .modal-body").html(content);
  $("#myModal").modal();
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<table>
<tbody
<tr>
    <td align='center'>socio1</td>
    <td align='right'>8/2/2018</td>
    <td align='left'>Juan Perez</td>
    <td align='center'><input type='button' value='Ver' class="ver"></td>
</tr>
<tr>
    <td align='center'>socio2</td>
    <td align='right'>8/3/2018</td>
    <td align='left'>John Smith</td>
    <td align='center'><input type='button' value='Ver' class="ver"></td>
</tr>
</tbody>
</table>

<div id="myModal" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Modal Header</h4>
      </div>
      <div class="modal-body">
        <p>Some text in the modal.</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>

  </div>
</div>
    
answered by 02.08.2018 в 21:05