On the page that I show below I am calling a php to pass the value of a field to me. When I do onclick in a row of my table the process works correctly, it brings me the comment field.
In an HTML segment I also have a button, which I need to work in the same way, but I have not succeeded, the file cumpl_alerta.php returns me undefined.
index.php
<script type="text/javascript">
function cumplir_alerta(id_entabla) {
var num_id2 = id_entabla;
if (num_id2 != "") {
$.post("cumplir_alerta.php", {valorBusqueda: num_id2},
function(mensaje) {
$("#comentario1").css('text-align','center');
$("#comentario1").html(mensaje);
});
};
};
<script>
<div id="fade" class="overlay"></div>
<div id="light" class="modal">
<p id="comentario1"></p>
<p id="botones_alerta">
<input type='button' value='Cumplido' id='cumplido' onclick="cumplir_alerta(<?=$id?>);">
<input type='button' value='Leído' id='leido' onclick="javascript:vw_nomostrar();"></p>
</div>
<?php
while (($fila = mysqli_fetch_array($result))!=NULL){
$id=trim($fila['id']);
$vsocio=trim($fila['numero_socio']);
$vcomentarios=trim($fila['observaciones']);
echo "<tr>\n";
echo " <td align='center'>". $vsocio . "</td>\n";
echo " <td align='left'>" .substr($vnombre . ", " . $vapellido,0,30) . "</td>\n";
if (strlen($vcomentarios) == 0 || $vcomentarios === '-'){
echo " <td align='center'><input type=\"button\" value=\" \" id=\"Ver2\" onclick=\"javascript:buscar('".$id."')\";></td>\n";
}else{
echo " <td align='center'><input type=\"button\" value=\"Ver\" id=\"Ver\" onclick=\"javascript:buscar('".$id."')\";></td>\n";
}
?>
cumpl_alerta.php
<?php
$consultaBusqueda = $_POST['valorBusqueda'];
$mensaje="OK ... EL ID ES " . $consultaBusqueda;
echo nl2br($mensaje);
?>
The latter I put together as to show what is necessary. What am I doing wrong?