Online Tutorials & Training Materials | STechies.com
Register Login
Advertisement

How to display an alert message box dialogue box using PHP

|| 0

How to display an alert message box dialogue box using PHP
Stechies

Alert boxes are special Java Script dialog boxes supported by the browsers. 

PHP does not support any such alert box pop-up messages because as we know PHP is a server-side language whereas an alert is rendered by the browser of the client. Therefore in order to pop an alert message via PHP, we need PHP to render the client browser through JavaScript (a client-side language).

Please follow the steps below in order to pop an alert message via PHP

Step 1) First we need to implement an alert or any other action in JS, as other JavaScript program do

Step 2) Now make PHP act as a data source using data format like JSON.

Note: This will allow you to separate the application code from its data and each programming language from the other.

Example 1

<?php  

  echo '<script Type="javascript">';
  echo 'alert("Message Delivered Successfully sent Java Script")';  //not showing an alert box.
  echo '</script>';
  exit;
?>

Output:

<script Type="javascript">alert("Message Delivered Successfully sent Java Script")</script>

Example 2

<?php

function_alert("We welcome the New World");

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

Output:

<script type='text/javascript'>alert('We welcome the New World');</script>

 


Advertisement
Advertisement
Advertisement