1
I need to clear a field img
and for this I am using the code below, but by clicking on button
javascript does not work because the page receives a refresh.
I have scanned the browser console and no error message appears... Can you tell me where I am missing??
Here’s the button code
<?php
// verificando o diretorio utilizado para fins de desenvolvimento
diretorio();
if(Empty($dir)){
$img_padrao = '/images/sem_imagem.jpeg';
}else{
$img_padrao = '/'.$dir.'/images/sem_imagem.jpeg';
}
?>
<img src='<?=$img_padrao?>' class='img-thumbnail limpar' id="img" alt="Img Destaque">
<button id="apagar" onclick="clearimg('<?=$img_padrao?>')" class="btn btn-danger tabindex='4'">Remover Imagem</button>
here the javascript
// função responsavel por apagar a imagem do Box (exibir a imagem padrão).
function clearimg($img_padrao){
var clearimg = $img_padrao;
$('.limpar').attr('src', clearimg);
}
Is that button inside some form? It has to be the button tag?
– Diego Marques
is inside a form yes, and does not need to be the tag button
– Diego Lela
you killed my problem! I switched to input and it worked... lack of experience disturbs and too.. Thank you! hugs!
– Diego Lela