开发者

Javascript confirm ain't working as it should

I have this js function that checks if OK or Cancel is pressed and returns false or true. What I am trying to do is that when is true to run the remaining js function in the order they appear but it isn't working; deleteList('$row->listID');updateList(); are never 开发者_JS百科executed.

Javascript:

function deleteConfirm(){
    if (confirm("Are you sure you wanna delete that list?")){
            return true;
    }
    else{
            return false;
    }

}

HTML:

<a href="#" id="listID" onclick="return deleteConfirm();deleteList('$row->listID');updateList();">

What am I doing wrong?

Thanks in advance.


It's because you're returning on the first statement (so the others never run), instead only hop out on a cancel, like this:

onclick="if(deleteConfirm()) { deleteList('$row->listID'); updateList(); }"

You can also greatly simplify your function, like this:

function deleteConfirm(){
  return confirm("Are you sure you wanna delete that list?");
}

...or if possible go the unobtrusive route, using data- attributes to get the listID.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜