<?php
//Clear the cache for form values
header('Cache-Control: no store, no-cache, must-revalidate');
header('Cache-Control: no store, no-cache, must-revalidate');
header('Pragma: no-cache');
//Load up functions
include "recon.php";
//Create the PHP Self Function
$username = $nohours = $noitem = $ipaddr = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = filter_input(INPUT_POST, "username", FILTER_SANITIZE_STRING);
$nohours = filter_input(INPUT_POST, "hours", FILTER_SANITIZE_NUMBER_INT);
$noitem = 0;
$xnoitem = filter_input(INPUT_POST, "itemselect", FILTER_SANITIZE_STRING);
if ($xnoitem === "item1") {
$noitem = 1;
}
$ipaddr = get_client_ip();
if(!empty($username)){
echo "Username is not null";
}
else{
echo '<script type="text/javascript">document.getElementById("warning").innerHTML = "New text!";</script>';
}
}
?>
<!DOCTYPE HTML>
<html>
<head>
<title> GGG Time Form </title>
<script type="text/javascript">
function outputUpdate(hours)
{
document.querySelector('#nohours').value = hours;
document.getElementById("total").innerHTML = "$" + hours * 3.75;
document.getElementById("item1").checked = false;
}
function xitem1()
{
document.getElementById("total").innerHTML = "$16";
}
</script>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div>
<div>
<h1 class="ctext">GGG Time Order Form</h1>
</div>
<div>
<p id="warning"></p>
</div>
</div>
<hr>
<div>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
(Enter your username you login with at GGG) Username:<span style="color:red;">*</span> <input type="text" name="username">
<br>
<br>
<label for="hourslider">Number of hours you would like to purchase: </label>
<input type="range" name="hours" min="1" max="24" value="12" id="hourslider" oninput="outputUpdate(value)">
<output for="hourslider" id="nohours">12</output>
<br>
<br>
<h3> Or select one of our packages below </h3>
<br>
<input type="radio" name="itemselect" value="item1" id="item1" onclick="xitem1()"> Day Pass $16.00
<hr>
<h3> Total payment owed: <p id="total">$0</p></h3>
<input type="submit">
<hr>
</form>
</div>
<div id="ipbox">
<span>For security purposes your ip address is being logged: <?php echo get_client_ip(); ?></span>
</div>
<div>
</div>
</body>
</html>
So on that logical statement below this text ( Also located in the code above) I'm wondering why when I echo out the javascript it's not changing the contents of the <p> element with the id of warning. I've tried looking everywhere for my answer and I'm sorry if this is a duplicate but any help would be appreciated...
if(!empty($username)){
echo "Username is not null";
}
else{
echo '<script type="text/javascript">document.getElementById("warning").innerHTML = "New text!";</script>';
}
warning <p>. If it doesn't match that condition, the variable with the text is empty, not showing anything.warningat the point your javascript is being loaded and executed