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")
}
                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");
}
                        you are pasing php variable to JS variable var currString = "";
and in window.location you are passing again php variable which is wrong,
so do it like this
window.location = "list.php?s=" + currString + "&=delete=true&id=" + a;
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With