echo
echo

Reputation: 89

JavaScript delete confirm box

My function is something like this:

function delete(type, id){
    if(id){
        window.location.href = '/site/'+type+'/delete/'+id;
    }
}

I'm calling it like this:

onclick="delete('position', <?php echo $key;?>)

Where in the function should I put the Confirm option?

Upvotes: 0

Views: 794

Answers (2)

Timoth&#233;e Groleau
Timoth&#233;e Groleau

Reputation: 1960

try this:

function deleteIt(type, id)
{
    if(id && confirm('Are you sure you want to delete?'))
    {
        window.location.href = '/site/'+type+'/delete/'+id;
    }
}

Upvotes: 2

Sirwan Afifi
Sirwan Afifi

Reputation: 10824

function delete(type, id)
{
    if(id && (confirm('Are you sure you want to delete?')))
    {
        window.location.href = '/site/'+type+'/delete/'+id;
    }
}

Upvotes: 0

Related Questions