Jump to content

Display Msg & Open Page


Ache

Recommended Posts

What I want is to show the user a message, wait a few seconds and then open a page in the same window.I got the code as below, but it is not working.It does wait and opens the page correctly, but the message is not shown.

if ($waarde == 1)	{	echo "Gebruikersnaam bestaat al";	sleep(5);	echo ("<script>window.location ='aanmelden.php';</script>");	}

Link to comment
Share on other sites

PHP code is all executed before the page is sent to the client (so all that script does is delay the response by five seconds). You could do the sort of thing you want in JS though:

document.getElementById("msg").innerHTML = "Gebruikersnaam bestaat al";setTimeout("window.location ='aanmelden.php'", 5000);

Link to comment
Share on other sites

Thanks. Got it working now.

if ($waarde == 1)	{	echo ("Gebruikersnaam bestaat al");	echo ("<script>setTimeout(\"window.location ='aanmelden.php'\", 5000);</script>");	exit();	}//more code can be placed here. But will not be executed if $waarde equals 1 (one)

Link to comment
Share on other sites

By the way, you don't need the parenthesis surrounding the parameter of echo, because it is a language construct and not technically a function. Parenthesis just slow things down.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...