01/10/2018, 12:25

Submit form trong javascript

Chào các anh chị , em có một chút vấn đề không biết làm sao để chạy submit khi em nhấn yes.
Cụ thể code em là :
JS:

document.getElementById('b2').onclick = function(e){
	e.preventDefault();
    swal({
        title: "Are you sure?",
        text: "Do you want create this account !",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: '#DD6B55',
        confirmButtonText: 'Yes, create it!',
        cancelButtonText: "No, cancel plx!",
        closeOnConfirm: false,
        closeOnCancel: false
    },
    function(isConfirm){
    if (isConfirm){
  //Chỗ này làm sao để submit cái form kia ạ
      swal("Created!", "This account has been creacted!", "success");
      
    } else {
      swal("Cancelled", "This account not be create :)", "error");
    }
    });
};

HTML

<form  name="add_new_user" method="POST">
     <button  id="b2" type="submit" name="submit" > Add new user</button>
</form>

Em đã xử lí được chỗ hiện js lên nhưng click yes để submit form thì chưa làm được, mong các cao nhân chỉ giúp em ạ !!!

明玉 viết 14:36 ngày 01/10/2018

https://www.w3schools.com/jsref/met_form_submit.asp
hoặc
https://www.w3schools.com/jquery/event_submit.asp

Bài liên quan
0