matthew s matthew s - 1 year ago 126
Javascript Question

Alert wont display with location

im trying to get error codes to generate with JS so that i dont have to use die. Im using the location function to refresh the page then create the alert but it wont display. It goes as follows:

header("Location: register.php");
$fields = "You did not complete all the required fields. Please try again.";
echo "<script type='text/javascript'>alert('$fields');</script>";

Answer Source
header("Location: register.php");

You instructed a location change before any outputs. Outputs will always be ignored in this case.

You may use:

header("Refresh: 10;url=register.php")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download