<?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>';
}
Mr Lister
46.8k15 gold badges118 silver badges156 bronze badges
1 Answer 1
"your basic problem is that it is executing, but none of your document has loaded yet. there is no element with the id of warning at the point your javascript is being loaded and executed" ~ Watcher
Sign up to request clarification or add additional context in comments.
Comments
default
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