Question

i'm having list of user with check box, so the function is at least one check box must select else validation done using jquery to delete selected user, once validation done there should confirm message box appear to ask confirmation wheter yes or no to delete. so below is my code without the confirm message box

  function delete(element,servlet,formName){
    var form = element.form;   
    $(document).ready(function() {  
    $(form ).validationEngine({  
      submitHandler: function(form) {    
       $(form).ajaxSubmit();    
   }   
  })   
 });   
}  

so where i should insert the confirm message box, thanks in advance

Was it helpful?

Solution

$(form).ajaxSubmit({
    success: function() {
        alert('user successfully deleted');
    }
});

OTHER TIPS

$("#deletebutton").bind('click', function(){
    if(confirm('delete?')){
        $('input:checked').each(function(){
            deleteFunction(this.id);
        });
    }
});

and the markup should be

<ul>
  <li><input type="checkbox" id="name_1" name="name_1" />name 1</li>
  <li><input type="checkbox" id="name_2" name="name_2" />name 2</li>
  <li><input type="checkbox" id="name_3" name="name_3" />name 3</li>
  <li><input type="checkbox" id="name_4" name="name_4" />name 4</li>
  <li><input type="checkbox" id="name_5" name="name_5" />name 5</li>
</ul>
<button id="deletebutton">del</button>

Put confirmation before the submit

submitHandler: function(form) {
    if (confirm("really delete that dude?")) {
        $(form).ajaxSubmit();
    }
}
function delete(element,servlet,formName){
    var form = element.form;   
    $(document).ready(function() {  
    $(form ).validationEngine({  
      submitHandler: function(form) {    
       $(form).ajaxSubmit({
          dataType:  'json', 
          success: function(data) {
              if (data.okDelete) // json response
                 alert('ok deleted');
              else
                 alert('error deleted');
          }
       });    
    }   
  })   
 });   
}  

I think you need jQuery dialog to show a confirmation dialog with some buttons. First, you define a div for the dialog. Then, the buttons which you want to show. With the function within it, the action if the button is clicked. Last, create a dialog. You can place the code as a replacement of line : $(form).ajaxSubmit();
So, you create a dialog before you submit the form. Hope this help.

var dialog_="<div title='Confirmation'><span class='ui-icon ui-icon-alert' style='float:left; margin:0 7px 20px 0;'></span>";

buttons_confirm['Yes']=function() {
   $(form).ajaxSubmit();
   $(this).dialog('close');
};
buttons_confirm['Cancel']=function() {
   $(this).dialog('close');
};
$(dialog_).dialog({
    bgiframe: true,
    resizable: false,
    modal: true,
    buttons: buttons_confirm                
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top