I would like to insert a javascript alert in my action button

0

first the action call to delete

<?php
$aux = 0;
while($resultado = mysql_fetch_object($query))
{
$url_alterar = "form_alterar.php?cod=".$resultado->id;
$url_excluir = "excluir_cad.php?cod=".$resultado->id;
if ($aux % 2 == 0)

Now the action button

<?="<td><a href=".$url_excluir."><img src='delete.jpg' height='35' width='35'></a></td>";?>

I got this code here on the internet

<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
decisao = confirm("Clique em um botão!");
if (decisao){
alert ("Você Apagou o Registro,\n"+decisao);
} else {
alert ("Voce CANCELOU,\n"+decisao);
}
</SCRIPT>

I have tried it anyway without success, I believe that the way it sends the variable to the system would not allow it to use this jscript resource. I already tried to use direct in the action of the button but it did not give result, neither in the page that is called or in the code explained above. I am asking for help because on September 27 I present my work in college and would like to 'spruce' since everything works perfectly. Thank you for helping me! hugs

    
asked by anonymous 22.09.2016 / 06:00

1 answer

1

Inline example:

<a href="delete.php" onclick="return confirm('Prosseguir com a ação?');">excluir</a>

To be clearer, for you:

<?="<td><a href=".$url_excluir." onclick="return confirm('Prosseguir com a ação?');><img src='delete.jpg' height='35' width='35'></a></td>";?>

Then the <script>...</script> excerpt can be deleted.


I'll just suggest you change a little.

<td><a href="<?php echo $url_excluir;?>" onclick="return confirm('Prosseguir com a ação?');><img src='delete.jpg' height='35' width='35'></a></td>
                                    
22.09.2016 / 06:21