How to ask the reason for a deletion using confirm and prompt?

Asked

Viewed 38 times

2

I have a project ready and I need to make a change. When I delete a record I callprint "javascript:if(confirm('" . $msg . "'))";, however I need to ask the reason for the deletion. I would like to ask this reason with a prompt.

The user will click the button, and a prompt will appear asking the reason for the deletion. If fill and click ok, I take this amount and forward with href:

<a href=" <?php msg("Deseja desvincular associado?") ?>
          {location='?pagina=alu&acao=excluir&
          cd_aluno=<?php echo $oquefazer->registros->cd_aluno; ?>';}">
          <button class="btn"><p class="icon-remove-sign"></p></button>
</a>
  • 1

    You can use ajax?

  • 1

    Thank you. I made a gambit and resolved

1 answer

1

You can use the function prompt javascript

console.log(mostrarPrompt());

function mostrarPrompt() {
  var motivo = prompt('Informe o motivo');
  if (motivo === '')
    mostrarPrompt();
  if (motivo !== null)
    return motivo;
  return null;
}

  • Thank you. I made a gambit and resolved

  • @Klebersouza posts his solution in an answer so he can help other people who may later have the same problem :) And don’t forget to accept your answer so it doesn’t get pending. ;)

  • how to pass Javascript variable to PHP ?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.