0

Does anyone know if there is a way of getting javascript to wait until I have pressed ok on an alert before it runs the next line of code?

The site I am developing is in PHP but I have made this function to bring up a message box:

function message($msg) {
        echo "<script language='javascript' type='text/javascript'>";
        echo "alert('".$msg."');";
        echo "</script>";
}

This is fine unless I change the header location in the next line in PHP as it automatically changes the page with showing the message.

Any suggestions?

Edited by Dani: Formatting fixed

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

This is fine unless I change the header location in the next line in PHP as it automatically changes the page with showing the message.

Can you post the code with that line in place please, so I can see exactly what is going on?

Airshow

0
if ($save=="new") { //New user
    $id=$_POST["username"];
    $password=generatePassword(8,8);
    $sql="INSERT INTO admin_users (username, password, email, accept_bookings, decline_bookings, remove_customers, amend_user, view_admin_log, view_error_log)
    VALUES('".$id."', '".$password."', '".$email."', '".$accept_bookings."', '".$decline_bookings."', '"
    .$remove_customers."', '".$amend_user."', '".$view_admin_log."', '".$view_error_log."');";
    $result = query_db($sql);
    // email user
    message("User created!, new password has been sent to user.");
    update_admin_log($user,"Users","User ".$id." created");
} else { //Amend user
    $id=$save;
    $sql="UPDATE admin_users 
    SET email='".$email."', accept_bookings='".$accept_bookings."', decline_bookings='".$decline_bookings."', remove_customers='"
    .$remove_customers."', amend_user='".$amend_user."', view_admin_log='".$view_admin_log."', view_error_log='".$view_error_log."' 
    WHERE username='".$id."';";
    $result = query_db($sql);
    // email user
    message("User details amended.");
    update_admin_log($user,"Users","User ".$save." details amend");
}
close_db();
header("location:admin_users.php");

Edited by Dani: Formatting fixed

0

Nathan,

In my experience, alerts suspend javascript execution in all browsers (though I have an old Javascritpt book that says otherwise). Therefore, I can't immediately see why the earlier alert should not suppress the later one.

message() is not native php. From what you say, it appears to write something into the served page that causes a Javascript alert.

Try "view source" in the browser to see the HTML/Javascript that is actually served.

Airshow

Edited by Airshow: n/a

This topic has been dead for over six months. 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.