Welcome Guest, Not a member yet? Register   Sign In
jQuery Delete Confirmation
#11

[eluser]lefoup[/eluser]
[quote author="Kemik" date="1201831399"]Thanks guys.

To pass a variable could I just do:
Code:
&lt;a href="#" onclick="return deletechecked('Are you sure you want to delete &lt;?=$row-&gt;username ?&gt;');">Delete checked messages</a>
Javascript
Code:
function deletechecked(message)
{
    var answer = confirm(message)
    if (answer){
        document.messages.submit();
    }
    
    return false;  
}
[/quote]

I'll add my appreciation too. Very helpful, thanks a lot!
#12

[eluser]skunkbad[/eluser]
I can't really take the time to explain how this works, but my javascript uses ajax to connect to another method in my controller, and that method calls a delete method in a model. If the delete method was successful, then it passes a confirmation back to the controller, which sends it back as the ajax response. I can then mark the row as deleted:

Code:
$('.delete-img').live('click', function(){
    var answer = confirm('Delete: ' + $(this).parent().next().next().next().html() + '?');
    if(answer){
        var rand_chars = randomString(16);
        $.cookie('csrf_token', rand_chars, {path: '/', domain: '&lt;?php echo $_SERVER['HTTP_HOST']; ?&gt;'});
        tr_id = $(this).parent().parent().attr('id');
        path = $(this).parent().next().next().next().html();
        $.post(
            '/&lt;?php echo $delete_method; ?&gt;/',
            {
                csrf_token: rand_chars,
                id: tr_id,
                path: path,
                standAlone: 1
            },
            function(data){
                if(data.test == 'success'){
                    $('#' + tr_id).addClass('pink');
                    $('#delete-confirmation p')
                        .css('display', 'block')
                        .html('MARKED ROWS HAVE BEEN DELETED')
                        .delay(2500)
                        .fadeOut('slow');
                }
            },
            'json'
        );
    }else{
        alert($(this).parent().next().next().next().html() + ' was not deleted');
    }
});
function randomString(length){
    var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz'.split('');
    if (! length) {
        length = Math.floor(Math.random() * chars.length);
    }
    var str = '';
    for (var i = 0; i < length; i++) {
        str += chars[Math.floor(Math.random() * chars.length)];
    }
    return str;
}

The nice thing with this code is that I can adapt it to any type of user, photo, file, or anything else that I want may want to delete.
#13

[eluser]CodeIgniteMe[/eluser]
You can use the jQuery UI Library. (http://jqueryui.com)
It has a dialog box that is totally customizable. You can have your own title and message (html/css formatted) and your own custom buttons and button texts. Cool!
#14

[eluser]Amitabh Roy[/eluser]
[quote author="OOP-MVC addict" date="1309525670"]You can use the jQuery UI Library. (http://jqueryui.com)
It has a dialog box that is totally customizable. You can have your own title and message (html/css formatted) and your own custom buttons and button texts. Cool![/quote]


+1 for jquery UI




Theme © iAndrew 2016 - Forum software by © MyBB