Question

How can I make a popup alert window in a php site, depending by a variable, not by clicking a link or button?

example:

if ($a==1) {
alert(Good value!);
}else{
alert(Wrong value!);
}
Was it helpful?

Solution

PHP itself can't interact with the client. You will have to have the PHP script output a JavaScript solution.

echo '<script type="text/javascript">';
if ($a==1) {  
  echo "alert('Good value!');";
}else{
  echo "alert('Wrong value!');";
}
echo '</script>';

OTHER TIPS

Not a realy smart solution... People with a popup blocker wont see the popup... I prefer to jQuery with some HTML and PHP. If you wanne use it with POST data, try some AJAX, realy helps a lot. If you wanne use it for a POST, i can write you a small piece of code if you would like, let me know

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top