Jquery Dialog Delete row

I would just need help for a small part using jquery and dialog box. I have been looking around for days, unfortunately never found something that goes reasonably easy and quick.

I want to click a "button", then a jquery dialog box, where I then asked if I would like to delete this entry in the database will appear.

the box appears with "delete" and "chancel".

When I click on "delete" button, the record should be cleared out of the database.

This is my dialog javascript for delete.

<script>
$(document).ready(function() {
$( "#user_delete" ).dialog({
    draggable:true,
    resizable: false,
    minHeight:600,
    minWidth:900,
    modal: true,
    bgiframe: true,
    position: ['center',20],
    buttons : {
        Delete: function() {$("#user_delete > form").submit();
        $(this).dialog('close');},
        Chancel: function() {$(this).dialog('close');}
        }});

});
</script>

This is my normal code for the page (just the important things)

...
while ($row_user = mysqli_fetch_array($sql)){

echo '<div class="user_id">';
echo $row_user['user_id'];
echo '</div>'; 

echo '<div class="user_delete">';
echo '<input type="submit" name="user_delete'.$row_user['user_id'].'" class="icon_user_delete" value="">';
echo '</div>'; 
}
...

if (isset($_POST['user_delete'.$row_user['user_id'].''])){

echo '<div id="user_delete" title="Delete User '.$row_user['user_id'].'">';
echo $row_user['user_id'];
echo '</div>';

}

How can i solve this easily and quickly ?

Answers


Try This

$(document).ready(function() {
    $( "#user_delete" ).click(function(){
    $( "#user_delete" ).attr('title', 'Are you sure you want to delete?').dialog({
        height: 900,
        width: 600,
        modal: true,
        draggable:true,
        resizable: false,
        buttons : {
             "Confirm" : function() {
               $this.closest('form').submit();
        },
             "Cancel" : function() {
              $(this).dialog("close");
      }
  }

    }); 

});

I am not Your form class name is also

#user_delete
, so your function will fire even if you dont click on the button, but on the form.


Need Your Help

Rails - has_many :through - Create new record and association in one form

ruby-on-rails-4 nested-forms has-many-through form-for fields-for

I am currently struggling with a has_many :through association in my project. The basics of the association are as follows:

jQuery/Javascript - Get value of text input field, and display in div

javascript jquery

I am testing getting a text input, and printing the result in a div below. However, I can't see to get it to work.