vick
vick

Reputation: 957

Confirm box when link is clicked

<script type="text/javascript">
    $("a.route").live('click', function() { // live is better
        $("#results").load( $(this).attr('href') );
        return false;
    });
</script>  

That's the code, how can I incorporate the code you just gave me?

Upvotes: 1

Views: 292

Answers (2)

meo
meo

Reputation: 31249

if you want to use a custom box you could do it like that:

test link: http://jsfiddle.net/myDry/

function blockmeornot(extlink) {
    var oherf = $(extlink).attr('href')
    var msgboxID = 'areyousure'
    var msgbox = '<div id="' + msgboxID +'"><div><p> put your message here </p><a class="yes" href="' + oherf + '"> yes </a> <a class="no" href="#"> no </a></div></div>'
    $('body').append(msgbox)
    $('#' + msgboxID + ' a.no').live('click', function(){ $('#' + msgboxID).fadeOut(400, function(){$(this).remove()}) })
}

$('a.external').click(function(){ blockmeornot(this); return false })

Upvotes: 0

Dexter
Dexter

Reputation: 18452

The Confirm dialog returns true if the user clicks the OK button, or false if the user clicks on the Cancel button. You can use this value to trigger your script if they've clicked OK like this:

<script type="text/javascript">
    $("a.route").live('click', function() {
        if (confirm("Are you sure?")) {
            $("#results").load( $(this).attr('href') );
        }
        return false;
    });
</script>

Upvotes: 2

Related Questions