Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

160
Visualizações
Trying to make Yes/No javascript popup but is not working

hello i am trying to make popup Yes/No in js but is not working, this is my code:

one version is this:

if($admin==1) 
    print('<td><a href="delete.php?id='.$value. '"> <BUTTON class="btn btn-outline-info" onclick="AlertPopUp()" ><i class="fa fa-trash" style="color: #000000;"></i>  </BUTTON></a>');

function AlertPopUp(){
    let AlertPopUp = confirm("Are you sure you want to delete this client?");
    if(AlertPopUp){
        window.open('delete.php?id='+$value);
    }else{
        return;
    }
}

This is working but if i press cancel still deletes the value so i tried making the window.open but the url gets the value from php $value so i dont know how to pass it.

The other method i tried is this:

if($admin==1) 
    print('<td><a href="delete.php?id='.$value. '" onclick="return confirm('Are you sure you want to delete this client?');"> <BUTTON class="btn btn-outline-info" onclick="AlertPopUp()" ><i class="fa fa-trash" style="color: #000000;"></i>  </BUTTON></a>');

but this isnt working at all no popup appearing and the text isnt correct with ' ' so i tried " " but still nothing.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

As far as I understand you are working inside a PHP page, so it would be like this: first of all remove the <a> </a> and leave only the button because otherwise the link found in href will be opened.

<? php $ admin = 1;  if ($ admin == 1) print ('<BUTTON class = "btn btn-outline-info" onclick = "AlertPopUp ()"> <i class = "fa-trash" style = "color: # 000000;" > </i> </BUTTON> '); ?>

// then we harp the JS script

<script>
function AlertPopUp(){
    let AlertPopUp = confirm("Are you sure you want to delete this client?");
    if(AlertPopUp){
        window.open('delete.php?id=<?= $value ?>');
    }else{
        return;
    }
}
about 4 years ago · Juan Pablo Isaza Relatório

0

This is a very simple demo for your logic. It's not clear why it didn't work to you, despite the invalid html, considering that if the popup showed up it still should have the true/false behaviour.

Anyway I would suggest you didn't use the window.open strategy for running the server side action to delete the item. That's for sure an ajax request what you need.

function alertPopup(){
  let o = confirm("Are you sure you want to delete this client?");    

  if(o){
      console.log('make an ajax request to the url action (eg.: /delete.php?args');
  }else{
      console.log('changed my mind');
  }
}
button{
  cursor: pointer;
}
<button onclick="alertPopup();">Test me</button>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda