javascript help

Soldato
Joined
1 Feb 2006
Posts
8,188
hi,

need some help with a javascript function i am writing. This is what I have so far:

Code:
<script language="javascript" type="text/javascript" >
	function confirm_delete() {
		if (confirm('Proceeding with this task will permanently delete some files from your server. Continue?')) {
			alert('This theme will now be deleted');	
		}
		else {
			alert('You will now be redirected back to the previous page');
			history.go(-1);
			break;
		}
	}
</script>

HTML page with php echoing some stuff from a query:
Code:
<a href="delete_theme.php?theme=' .$row['themeID'] . '" onclick="confirm_delete()">

The story is that I have a php file which dynamically generates links to perform a delete of each file. I have set the link onclick to point to the above javascript. The confirm window pops up ok but when I click on cancel it still proceeds with the file delete i.e. it continues to follow the link. How can I stop this from happening? I thought whenever I used the history -1 in the javascript that the php page would no longer execute?

Would appreciate some help on this!

Cheers
 
i dont see why it would cause that problem, but i dont think you need a 'break;' in an if statement.
 
yeah i wasn't sure about the break either so i was just trying to see if that would stop executing everything else on the page but it didn't. Can't work out the problem. I should have added that it does redirect me back but that is after it has already jumped to the page in the link and deleted my file.
 
what does the "alert()" method do? i'v never used it.
Assuming, by its name, that it only shows that text and nothing else, then your if statement doesnt really do anything functional?
 
alert is just another kind of popup window which presents the viewer with a message and you just click on OK to continue.

edit: sorry didn't really explain enough. The purpose of the if statement is that when ok is clicked on the script will continue to run i.e. follow the link. If cancel is clicked on I want to go back to the previous page. You get what I'm saying?
 
Last edited:
yeah it's probably something very simple that is wrong but I just can't get it. If I click OK on the confirm window everything works fine. The problem is only when I hit cancel.

edit: think i have a solution

Code:
onclick="javascript:return*confirm('Are*you*sure*you*want*to*delete this theme?')"

This seems to work fine and there is no need to even call another script.

Appreciate the help.
 
Last edited:
what does your confirm() method look like? (is it even yours or is it a standard java method?)
 
Back
Top Bottom