I am trying to make it so a user enters something into a textarea, and once the user submits it, the content will immediately display inside of a div above whose id is "currentMessage". Here is the php file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Message Page</title>
<link rel="stylesheet" href="styles.css" type="text/css"/>
<script type="text/javascript">
function loadMessage(){
document.getElementById("currentMessage").innerHTML = "<?php
$my_file = "msg.txt";
$handle = fopen($my_file, "r");
$data = fread($handle, filesize($my_file));
fclose($handle);
echo $data;
?>";
}
</script>
</head>
<body onload="loadMessage();">
<?php include "header.html";?>
<div>
<div class="PageTitle">Messaging</div>
<p class="Paragraph">
Here you can send a message to the LCD display so that it may be shown when the display
cycles through its time, temperature and status.
</p>
<div class="Paragraph">
Current Message:<br>
<p id="currentMessage" class="CodeBlock"></p>
</div>
<div class="SubTitle">Enter Your Message:</div>
<form method="post" action="<?php echo $_SERVER["PHP_SELF"];?>" style="clear: left;">
<textarea cols="32" rows="3" name="msg" maxlength="96" id="msg"></textarea><br>
<input type="submit" value="Submit Message" name="submit">
</form>
<?php
if (isset($_POST['submit'])){
$msg = $_POST["msg"];
$my_file = "msg.txt";
$handle = fopen($my_file, "w") or die("Cannot open file: " . $my_file);
fwrite($handle, $msg);
fclose($handle);
echo "<script>
loadMessage();
</script>";
}
?>
</div>
</body>
</html>