Hi,
This is is my php:

<?php

 if($_SERVER['REQUEST_METHOD'] == 'POST')
{
   echo '<h1>' . $_POST['word'] . '</h1>';
   echo '<p>' . $_POST['sentence'] . '</p>';
}
else
{
  echo 'Invalid request';
} 
?>

How can I get the echo displayed in a CSS box or Javascript popup window.
Any help appreciated.
Thanks

Recommended Answers

All 2 Replies

Hello, for a javascript popup window you just do this

echo "<script type='text/javascript'>alert('<h1>'". $_POST['word']."'</h1>')</script>";
Member Avatar for diafol

Any php-derived html/text can be placed anywhere in your page (js, styling, html element). However, php is not interactive like js, so if you want interactivity, e,g, drawing data from the server as the user interacts with the page, you will need to use Ajax.

In a simple case, store the text you want to display in a (string) variable:

if(isset($_POST['word']) && isset($_POST['sentence']) && trim($_POST['word']) && trim($_POST['sentence']))
{
    $string  = "<h1>{$_POST['word']}</h1>\n<p>{$_POST['sentence']}</p>";
}
else
{
    $string = '<p>Invalid request</p>';
} 

Then where you need to place it...

<div class="myPopUp">
    <?php echo $string;?>
</div>

If this is an all in one page you may find that you get "Invalid Request" on page load before the form has been posted. In which case the code needs to be modified a little.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.