0

Hello all,

I have a php function that deletes the contents of a database table that relies on a javascript confirm box to tell it what to do as follows

javascript function as follows

function deleteMasterList()
{
	var outcome = confirm("Delete Master List, you will have to re-enter all band genres");
	
	if(outcome)
	{
		alert(outcome);
		<?php removeFromMasterList ?>		
	}
}

I now know this won't work as it will execute the php no matter what so I did this

function deleteMasterList()
{
	var outcome = confirm("Delete Master List, you will have to re-enter all band genres");
	
	if(outcome)
	{
		alert(outcome);
		window.location = "http://localhost/AA_Directory_Reader/delete.php" ;
			
	}
}

which is going to take me to a page that deletes the data from the database base then redirects back to the main page

except it does not take me there or to any other working web url I enter

this is the form i call it with

echo '<form action="index.php" method="post"  onSubmit="return(deleteMasterList())">';
echo '<input type="submit" name="delete_master_list" value="Delete Master List" /><br / >';
echo '</form>';

ideally I would like it to be one button press to get the confirm box to appear and then another to confirm or cancel, most examples I can find online use <a href> to link and do it via link to call there page not javascript

any ideas ?

cheers

Edited by mr_scooby: n/a

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by mr_scooby
0

Did it like this,

echo '<input type="button" value="Delete Master List" onclick="deleteMasterList()"/>';

which calls this java function

function deleteMasterList()
{
    var yes = confirm("Delete Master List ??");
    if(yes)
    {
        window.location="delete.php";
    }
}

which if yes is clicked takes you to this page which simply deletes the data then returns you to main page

<?php
include('commonDirFunctions.php');
removeFromMasterList();
header("Location: index.php");
?>

Edited by mike_2000_17: Fixed formatting

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.