Confirm before making the change

Asked

Viewed 38 times

-1

When I change the event on the calendar, before changing ask to confirm: the code:

function edit(event){
            start = event.start.format('YYYY-MM-DD HH:mm:ss');
            if(event.end){
                end = event.end.format('YYYY-MM-DD HH:mm:ss');
            }else{
                end = start;
            }

            id =  event.id;

            Event = [];
            Event[0] = id;
            Event[1] = start;
            Event[2] = end;

            $.ajax({
             url: './updatehoradataeventoLar',
             type: "POST",
             data: {Event:Event},
             success: function(rep) {
                    if(rep == 'OK'){
                        alert('Atividade Guardada correctamente');
                    }else{
                        alert('Tente novamente!'); 
                    }
                }
            });
        }

This way only warns that the activity has been stored correctly, but before appearing this alert I want to appear asking if you really want to change the event, if yes changes if it is not maintains.

The answers to this question did not help me to resolve my question, because in my case, when I make the change is by dragging the event already marked and I have no button or link to add the onclick and intended to do the same within the sucess of ajax

  • Possible duplicate of Ask before deleting database data

  • Before performing the entire function edit you wish to perform a confirmation?

  • @Pedro Paulo, yes, before making change ask for confirmation if you really want to make this change

  • Then search by function confirm. It is the solution, not an "onclick button".

  • Take a look at this answer that has a confirm: https://answall.com/a/74705/8063

1 answer

2


Use the function confirm(mensagem) to know if the user has confirmed the editing action:

function edit(event){
    if(confirm('Confirma a alteração dos dados?')) {
        start = event.start.format('YYYY-MM-DD HH:mm:ss');
        if(event.end){
            end = event.end.format('YYYY-MM-DD HH:mm:ss');
        }else{
            end = start;
        }

        id =  event.id;

        Event = [];
        Event[0] = id;
        Event[1] = start;
        Event[2] = end;

        $.ajax({
         url: './updatehoradataeventoLar',
         type: "POST",
         data: {Event:Event},
         success: function(rep) {
                if(rep == 'OK'){
                    alert('Atividade Guardada correctamente');
                }else{
                    alert('Tente novamente!'); 
                }
            }
        });
  }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.