I want to make it so that when a user clicks on a link and a window appears for him:

<script type="text/javascript"> var delete=prompt("Что бы подтвердить удаление введите слово "удалить", "")) if(delete=="удалить") тут выполняем часть пхп скрипта else тут тоже выполняем часть пхп скрипта </script> 

Who knows how to implement this correctly ??

  • one
    Using AJAX - zhenyab
  • @zhenyab, I agree, it is not advisable to use other options - mountpoint

1 answer 1

 js: <script> $(document).ready(function(){ $("#delete").click(function(){ var delete=promt("Что бы подтвердить удаление введите слово 'удалить'", ""); if(delete=="удалить") $.get("action.php", "data=1"); }); }); </script> php: <? include('db.php'); // пусть тут лежать подключения к базе данных $data = mysql_real_escape_string($_POST['data']); mysql_query('DELETE FROM `table_name` WHERE `id`='.$data); ?> 
  • pasted - link button in front of the script but when clicked, the window is not displayed oO <a id="delete" href="#"> Click me </a> <script> $ (document) .ready (function () {$ ("# delete "). click (function () {var delete = promt (" To confirm the deletion, enter the word "delete" "," "); if (delete ==" delete ") $ .get (" action.php ", "data = 1");});}); </ script> - DanteLoL
  • First, delete is an operator. It cannot be used as a variable. Secondly, not "promt", but "prompt". Just in case, here is the working code: <script> $ (document) .ready (function () {$ ("# delete"). Click (function () {var del = prompt ("To confirm the deletion, enter the word 'delete '"," "); if (del ==" delete ") $ .get (" action.php "," data = 1 ");});}); </ script> <a id="delete" href="#"> Click me </a> - Arc
  • still not displayed (( - DanteLoL
  • rave. Skip all code completely. - Arc
  • 3
    My personal opinion would be to connect jQuery before using it. - Arc