Pass PHP Variable into Java Script window.location

javascript, php, window.location

Solution

Try this:

function confirmation(a) {
    var currString = "<?php echo $currString ?>";
    var answer = confirm("Are you sure you want to delete this item?");
    if (answer){
        alert("The item has been deleted")
        window.location = "list.php?s=" + currString + "&=delete=true&id=" + a;
    }
    else{
        alert("The item has not been deleted");
}

Problem

I am trying to pass a php variable into a java script window.location that returns a user to the current list view after deleting an item from the database. I can't seem to get the syntax correct. Code: ``` function confirmation(a) { var currString = "<? echo $currString ?>"; var answer = confirm("Are you sure you want to delete this item?") if (answer){ alert("The item has been deleted") window.location = "list.php?s='. $currString .'&=delete=true&id=" + a; } else{ alert("The item has not been deleted") } ```

Original source