Deletion Confirmation Prompt with Javascript and ASP

2

I have a list of titles dynamically presented to the user:

[ x ] - [ + ] - Título 1
[ x ] - [ + ] - Título 2
[ x ] - [ + ] - Título 3
[ x ] - [ + ] - Título 4

The number of items is variable and the values for Title are also dependent on the user's previous choices.

The first button [ X ] is for DELETE the record, the second [ + ] is for EDIT .

DELETE I need a% window that will CONFIRME delete the registry.

I did so: Prompt

But the two buttons on the prompt do the same thing. This is OK delete and CANCEL too.

Does anyone have any idea how to make this work?

    
asked by anonymous 07.08.2015 / 06:40

3 answers

1

Use your onclick event as follows:

onclick="return confirm('Deseja realmente excluir?')"

When this event returns false , the behavior is similar to calling event.preventDefault();

I do not know ASP, but I researched and found that to use double quotes in an ASP string, just duplicate them:

Response.Write(" onclick=""return confirm('Deseja realmente excluir?')""")

In any case, I suggest leaving this part of the code outside of ASP by closing the tag before and then reopening:

%> onclick="return confirm('Deseja realmente excluir?')"<%
    
08.08.2015 / 04:19
2
function cConfirm(str, link) {
    if (window.confirm(str)) {
        window.location.href = link;
    } else {
        // código que queres executar caso sepra pessionado CANCEL
    }
}

Then instead of directly calling window.confirm in your element, you use onClick="javascript:cConfirm('Deseja realmente excluir?','?edit=true&id=1')"

explaining: window.confirm returns boolean when you load on any of the buttons - returned true whether OK or false in case of CANCEL

    
07.08.2015 / 14:23
0

Thanks guys,

I've put together elements of the two responses.

MoshMage's cConfirm function.

From w35l3y the hint about leaving the call to function OUT of the ASP block and handling the event in case of FALSE.

 <script type="text/javascript">
     function cConfirm(str, lnk) {
        if (window.confirm(str)) {
            window.location.href = lnk;
        } else {
            event.preventDefault();
        }
    }
</script> 

And the call to the function was:

        %>
        onClick="javascript:cConfirm('Deseja realmente excluir?','delete.asp?pagina=<%=pag%>&NID=<%=RStemp("news_id")%>')">
        <%

Thank you for your patience and willingness to help.

Thanks!

    
10.08.2015 / 04:47