Javascript help please

Associate
Joined
28 Feb 2007
Posts
969
Location
Leeds/Sunderland
Im trying to get the popup to redirect to a page when cancel is pressed and carry on is ok is pressed.

Code:
<script type="text/javascript">
function disp_confirm()
{
var r=confirm("Are you sure you want to delete your account");
if (r==true)
  {
	
  }
else
  {
	
  }
}
</script>
ive tried loads of things inbetween the if anf else but i cant get it to work

help please :(
 
Where are you displaying it? Surely the page should redirect to a page (ie. delete script) if ok is pressed and do nothing if cancel is pressed?
 
with the above code if i press either ok or cancel it will carry on what its doing and redirect me to the page i want when ok is pressed.
but i want cancel to direct me to a different page as ok
 
Last edited:
this is the form
PHP:
print"<form method='POST' action='logined.php'>";
print"<td><u>Username</u><br />";
print "$username ";
print"<input type='checkbox'  value='$username' name='del' ></td>";
print"</table>";
print"<table align='center' bgcolor='black' font='white' >";
print"<td><input type='submit' onclick='disp_confirm()' value='Delete Account' name='dele'></td>";
print"</form>";

and the page which it currently redirects to
PHP:
<?php


	$connection = mysql_connect("localhost","root","");
	mysql_select_db("esound",$connection);	
	
		if (isset($_POST['dele']))
	{
			mysql_query("DELETE FROM members WHERE Username = '$_POST[del]' ");
			header('Location: login.php');
	}
		
	mysql_close($connection);
	
?>
 
Code:
<!-- CHANGE FORM TAG TO THIS -->
<form name="frmDelete" method='POST' action='logined.php'>

...

<script type="text/javascript">
	function disp_confirm() {

		if (confirm("Are you sure you want to delete your account")) {
			document.frmDelete.submit();
		}
		else {
			// redirect on cancel
			window.location.assign('somewhere-else.php');
		}
	}
</script>

*edit actually you need to submit the form, not navigate to a different page on OK - code amended.

You'll also need to ensure that the checkbox is ticked - I'll let you google the answer for that one ;)
 
Last edited:
Your reply just said "..." before you edited it.

Ye i wrote something completely wrong.


Code:
<!-- CHANGE FORM TAG TO THIS -->
<form name="frmDelete" method='POST' action='logined.php'>

...

<script type="text/javascript">
	function disp_confirm() {

		if (confirm("Are you sure you want to delete your account")) {
			document.frmDelete.submit();
		}
		else {
			// redirect on cancel
			window.location.assign('somewhere-else.php');
		}
	}
</script>

*edit actually you need to submit the form, not navigate to a different page on OK - code amended.

You'll also need to ensure that the checkbox is ticked - I'll let you google the answer for that one ;)
It doesn't work

it must be something other than the script
 
Last edited:
Back
Top Bottom