try this:
function deletePost() {
var ask = window.confirm("Are you sure you want to delete this post?");
if (ask) {
window.alert("This post was successfully deleted.");
window.location.href = "window-location.html";
}
}
Answer from kingkode on Stack OverflowYou're missing semi-colons after your javascript lines. Also, window.location should have .href or .replace etc to redirect - See this post for more information.
echo '<script type="text/javascript">';
echo 'alert("review your answer");';
echo 'window.location.href = "index.php";';
echo '</script>';
For clarity, try leaving PHP tags for this:
?>
<script type="text/javascript">
alert("review your answer");
window.location.href = "index.php";
</script>
<?php
NOTE: semi colons on seperate lines are optional, but encouraged - however as in the comments below, PHP won't break lines in the first example here but will in the second, so semi-colons are required in the first example.
if (window.confirm('Really go to another page?'))
{
alert('message');
window.location = '/some/url';
}
else
{
die();
}
What do you mean by "make sure"?
alert('message');
window.location = '/some/url';
redirects user after they click OK in the alert window.
I suspect you mean in a confirm window (ie. Yes/No options).
if (window.confirm('Really go to another page?'))
{
// They clicked Yes
}
else
{
// They clicked no
}
What do you mean by "make sure"?
alert('message');
window.location = '/some/url';
redirects user after they click OK in the alert window.
I suspect you mean in a confirm window (ie. Yes/No options).
if (window.confirm('Really go to another page?'))
{
// They clicked Yes
}
else
{
// They clicked no
}
function YNconfirm() {
if (window.confirm('Really go to another page?'))
{
alert("You agree")
window.location.href = 'http:///mediclaim_portal/logout2.php';
}
}
then
<a href="/mediclaim_portal/logout2.php" onclick="YNconfirm(); return false;">Home</a>
The browser is navigating to the link after running your click handler.
You should change your handler to simply return false to cancel the navigation, and not set location at all.
function YNconfirm() {
if (window.confirm('Really go to another page?'))
{
alert("You agree")
window.location.href = 'http:///mediclaim_portal/logout2.php';
}
}
then
<a href="/mediclaim_portal/logout2.php" onclick="YNconfirm(); return false;">Home</a>
The browser is navigating to the link after running your click handler.
You should change your handler to simply return false to cancel the navigation, and not set location at all.
You want window.location.href = "http://localhost/project/index.php/Con_Group_View" not window.Location. Remember, names are case-sensitive in javascript.
Also note this is a duplicate of How to redirect to another webpage in JavaScript/jQuery?
It is
echo '<script type="text/javascript">';
echo'alert("Your Group Already Created ");';
echo 'window.location = "http://localhost/project/index.php/Con_Group_View";';
echo '</script>';
JavaScript is case-sensitive, there is a difference between window.location and window.Location
echo "<script>
alert('There are no fields to generate a report');
window.location.href='admin/ahm/panel';
</script>";
and get rid of redirect line below.
You were mixing up two different worlds.
use this code to redirect the page
echo "<script>alert('There are no fields to generate a report');document.location='admin/ahm/panel'</script>";
Use double quotes to wrap your onclick()
onclick="if
^
Modified Code
<a href ='create.php?monitor_id=$id' onclick="if(confirm('really?')) return true; else return false;"><center>DELETE</center></a>
As you have specific url to redirect on click you have to write as follow
<a href ='create.php?monitor_id=$id'
onclick="doConfirm()">
<center>DELETE</center></a>
<script tyle="text/javascript">
function doConfirm() {
if(confirm('really?')) {
window.location.href = "create.php?monitor_id=$id";
}
else {
return false;
}
}
</script>