javascript - how to add confirm message box into jquery - Stack Overflow

i'm having list of user with check box, so the function is at least one check box must select else

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

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

Share Improve this question edited Sep 29, 2010 at 15:07 Darin Dimitrov 1.0m275 gold badges3.3k silver badges2.9k bronze badges asked Sep 29, 2010 at 15:04 ApacheApache 1,8069 gold badges51 silver badges72 bronze badges
Add a ment  | 

5 Answers 5

Reset to default 2
$(form).ajaxSubmit({
    success: function() {
        alert('user successfully deleted');
    }
});
$("#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                
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745136186a4613209.html

相关推荐

  • javascript - how to add confirm message box into jquery - Stack Overflow

    i'm having list of user with check box, so the function is at least one check box must select else

    1小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信