I am trying to make a button that redirects only if a user confirms it. This is what I have so far.
Javascript:
function del_list(){
doIt=confirm('do you wish to proceed?');
if(doIt){
//DO SOMETHING
}
else{
//DON'T DO SOMETHING
}
}
HTML:
<a href=""><img src="icon.png" onclick="del_list()" border="0"></a>
Currently the page redirects whether the user confirms or not. I only want the page to redirect if the user confirms (clicks ok on the confirm popup).
If you want the onclick event to be cancelled, you’ll want to use preventDefault on the event itself or you can return false. You could modify your code to look something like this:
HTML