简体   繁体   中英

JavaScript confirm popup not working

I have a php file which is part of a basic Content Management System. Inside this file I have a table which contains a "Delete" link in every row.

What I am trying to do is create a choice popup in a javascript function of which I call when the link is clicked.

My function code (which appears in the head part of my php file) is below:

<script type="text/javascript">

function delete(skillID)
{
    var answer = confirm("Are you sure you want to delete this record?");
    if(answer == true)
    {
        window.location.href = "process/deleteRecord.php?skillID=" + skillID;
    }
}

The code which calls this function is below:

echo "<td><a href=\"javascript:delete({$rowSkills['skillID']})\">Delete</a></td>";

The problem is that the box doesn't even popup, so the function isn't called properly.

Can anyone help?

If there are any other details you need to know please let me know.

您可以尝试其他方法:

echo "<td><a href=\"process/deleteRecord.php?skillID={$rowSkills['skillID']}\" onclick=\"return(confirm('Are you sure you want to delete this record?'));\">Delete</a></td>";

You need to use the "onClick" attribute, try that :

echo "<td><a href=\"\" onClick=\"delete($rowSkills['skillID'])\">Delete</a></td>";

Hope it'll help!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM