在JavaScript警报/确认框中发送PHP变量

时间:2012-02-28 16:48:22

标签: php javascript variables alert

我一直在稳步前进,直到我希望用户有一个' 确认'在通过PHP删除行之前发出警报。基本上,我需要将行的id号的变量传递给' delete.php'用户按下“确定”后的页面。

所以PHP打印出一个按钮:

$clickid = $db_field['id'];
    print "<form><input type='button' onclick='confirmation()' value='Delete'></form>";

我的Javascript:

function confirmation() {
    var answer = confirm("You wish to delete this event?")
    if (answer){
        alert("Deleted")
        window.location = "http://www.xxxxxxx.co.uk/admin/delete.php<? "?id=$clickid "?>";
    }
    else{
        alert("Your Event is Not Deleted")
    }
}
</script>

它显然贯穿于'delete.php&#39;页面,但不会删除任何内容,因为$ clickid似乎没有传递给它的值。如果有人能够发现我出错的地方,或者某些可行的东西,那将会很有帮助。

2 个答案:

答案 0 :(得分:4)

window.location = "http://www.xxxxxxx.co.uk/admin/delete.php?id=<?php echo $clickid; ?>";

答案 1 :(得分:0)

window.location = "http://www.xxxxxxx.co.uk/admin/delete.php<? "?id=$clickid "?>";

这行不应该更像这样吗?

window.location = "http://www.xxxxxxx.co.uk/admin/delete.php?id="<?=$clickid ?>"";