Do not execute click event

1

This is the code that I have of the button (The variables are equal to the result of a query, I checked and they are fine):

 echo '<input type="button" value="ELIMINAR" class="btnForm" onClick="eliminar('.$idEvento.','.$nombre.')" /> ';

Now we see the code of the remove function:

function eliminar(id,nombre)
        {
            if(confirm('¿Estas seguro de que desea eliminar la actividad?')){
                location.href="eliminacion.php?id="+id+"&nombre="+nombre;
                return true;}
            else
                return false;
        }
                    
asked by tripossi 11.06.2016 в 17:56
source

2 answers

1

You save yourself problems if instead of echo, you close the key and place normal HTML. Also, it is more readable.

?> // cierre de php
<button class="btnForm" onClick="eliminar(<?=$idEvento?>, <?=$nombre?>)">Eliminar</button>
<?php // vuelves a abrir php y sigues
    
answered by 11.06.2016 в 20:47
0

I think you are not recognizing the quotes ( '' ) so you are not entering the event, try to do it this way

echo '<input type="button" value="ELIMINAR" class="btnForm" onClick="eliminar(\"'.$idEvento.'\",\"'.$nombre.'\")" /> ';

To send the data you could use , it would be something like that :

function eliminar(id,nombre){
  if(confirm('¿Estas seguro de que desea eliminar la actividad?')){

    $.ajax({
           url: 'eliminacion.php',
           type: 'POST',
           dataType: 'html',
           data: {
                  id: id,
                  nombre: nombre
           },
           success:function(respuesta){
             // respuesta, trae el array() o el mensaje dependiendo de el caso 
             return true;
           }
        });
   }else{
      return false;
   }
  }

To capture the data on the page you could do it with $ _ REQUEST [''] , I hope it helps you

    
answered by 11.06.2016 в 19:14