0

I'm trying to do this with JQuery. Below is my code. I have a form, with the id "delete". I would like a dialog to appear when a person hits the delete button confirming if this is what they would like to do. If they confirm, the default action happens, if they say no or x out of the dialog, i would like nothing to happen. Right now it the dialog box doesn't appear at all. Have any ideas?

 <form action="/delete/{{card.id}}" method="POST" id="delete">
          <button type="submit" class="btn pull-right">
              <p><span class="glyphicon glyphicon-remove"></span></p>
          </button>
        </form>
        <form action="/edit/{{card.id}}" method="POST">
          <button type="submit" class="btn pull-right">
              <p><span class="glyphicon glyphicon-pencil"></span></p>
          </button>
        </form>

      </div>
      <hr>
      {{card.content}}
    </div>
  {% endfor %}
{% endblock %}

{% block script %}
  $("#delete").submit(function() {
    return var confirm = confirm("Are you sure you want to delete?");
  });
{% endblock %}
Tara Lerias
  • 239
  • 1
  • 8

1 Answers1

0

Use this:

HTML:

<a href='#' class='delete' id='35'>Delete data</a>

JS:

$(".delete").click(function() {
    var id = (this).attr("id");
    if (confirm("Are you sure?")) {
        // do delete; use var id to delete data
    }
});

Instructions in the if block will be executed if user will press ok button. If he will press cancel button nothing will be happened.

In if block you can make an ajax-request to the php-script in which you will delete some data. Note, that you have to specify what data you want to delete.

Sharikov Vladislav
  • 7,049
  • 9
  • 50
  • 87