Search code examples
javascriptconfirm

JS: confirm() function take both answers OK and Cancel as true


I'm trying to use confirm() function in JS script to confirm important irrevercible actions that user do, such as deleting something by redirecting to corresponding link. But it doesn't matter what i click ok or cancel it takes it as true and redirect. Please help me to know what im doing wrong.

function confirm_boy() {
    if (confirm('are you really want to do what you are going to do?')) {
        redirect('http://example/?dosomething');
    }
}

Solution

  • You need to close off the if condition properly

    function confirm_boy() {
        if (confirm('are you really want to do what you are going to do?')) {
            redirect('http://example/?dosomething');
        }
    }