A
A
Alexander Andropov2020-04-15 09:49:03
PHP
Alexander Andropov, 2020-04-15 09:49:03

How to substitute the post ID in the modal window?

Good day.
I have a list of records that are pulled from a db.
Each entry has

<a class="delobj" href="handlers/delete_object.php?id_obj=13220" data-obj="13220"><img src="/img/icon_delete_object.png"></a>
a link leading to a handler that deletes a record from the database using the GET method.

There is a modal window
<div class="modal fade" id="default-example-modal-sm-center" tabindex="-1" role="dialog" style="display: none;" aria-hidden="true">
  <div class="modal-dialog modal-sm modal-dialog-centered" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">Вы точно хотите удалить запись?</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true"><i class="fal fa-times"></i></span>
        </button>
      </div>
      <div class="modal-body">
        текст сообщения
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary waves-effect waves-themed" data-dismiss="modal">Отмена</button>
        <button type="button" class="btn btn-primary waves-effect waves-themed">Удалить запись</button>
      </div>
    </div>
  </div>
</div>

How to make it so that by clicking on the link of the record that leads to deletion, a modal window appears, confirming the deletion and by clicking "Delete record" exactly the record that is equal to id_obj is deleted.

Thank you in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Romanov, 2020-04-15
@Serhioromano

<a class="delobj" href="javascript:void(0)" data-obj="13220">
    <img src="/img/icon_delete_object.png">
</a>
function($){
     $('.delobj').on('click', function(){
          if(confirm('Sure?')) {
               window.location.href = 'handlers/delete_object.php?id_obj=' + $(this).attr('data-obj')
          }
     })
}(jQuery)

I did not debug the code, I took it right here. There may be errors or typos, he idea should be clear.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question