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

Recommended Answers

try this

<a href="http://localhost/AA_Directory_Reader/delete.php" onClick="return confirm('Are you sure you want to delete this Entry?')">Delete</a>
Jump to Post

All 3 Replies

try this

<a href="http://localhost/AA_Directory_Reader/delete.php" onClick="return confirm('Are you sure you want to delete this Entry?')">Delete</a>

this works, but it is a link, which if given the choice I would prefer to do it by buttons.

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");
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.