Equivalent of Alert() and Prompt() in PHP

In JavaScript, we have Alert() and Prompt() which open up a popup box for the user.

Is there an equivalent for PHP? $Get_['asdf'] is one way to get user input... any others?

Also, one more question. Is it a requirement that PHP always be executed all at once? Or can it be like JavaScript, where it waits for the user input (e.g. popup box), then executes the rest of the code after that.

-------------Problems Reply------------

Nope, there is no equivalent. All php is executed on the server-side only. Unless you're using it at the command-line, which I doubt.

It also cannot wait for user input like javascript, like you wanted. Sorry. You'll have to use ajax for that.

PHP is a server side language, it can't do alert messages on the client side. But you can use javascript within the php to do the alert.

<script type="text/javascript">
window.alert("Hi There, I am the Alert Box!")

For Prompt you can do something like this -


//prompt function
function prompt($prompt_msg){
echo("<script type='text/javascript'> var answer = prompt('".$prompt_msg."'); </script>");

$answer = "<script type='text/javascript'> document.write(answer); </script>";

$prompt_msg = "Please type your name.";
$name = prompt($prompt_msg);

$output_msg = "Hello there ".$name."!";


Category:php Views:1 Time:2018-08-03
Tags: php alert prompt

Related post

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.107 (s). 11 q(s)