gpt4 book ai didi

javascript - 如何验证我的预订日期?

转载 作者:行者123 更新时间:2023-11-28 01:19:24 24 4
gpt4 key购买 nike

我做了一个预订表格,我需要一个日期验证。

如果日期小于当前日期,则应显示一条警告消息,提示“请选择一个更高的日期”,并留在页面上更改日期。但是我的警报有问题:当我选择一个更高的日期时,它仍然显示警报信息。

这是我的代码:

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="tcal.css" />
<link rel="stylesheet" type="text/css" href="style.css" />
<link href="bootstrap/css/bootstrap.css" rel="stylesheet"/>
<script type="text/javascript" src="tcal.js"></script>
<script>
function showUser(str) {
if (str=="") {
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}

</script>

<script>
function showCottage(str) {
if (str=="") {
document.getElementById("txtcot").innerHTML="";
return;
}
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("txtcot").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getcottage.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>

<?php
session_start();
$message=''; //error message
$reserve=@$_POST['reserve'];
$dayCount = date("d");
$year = date("Y");
$month = date("m");
$currentDate = $year.'-'.$month.'-'.$dayCount;

if ($reserve <= $currentDate){
?>
<script type="text/javascript">
function myFunction(){
alert("Please select a higher date!");
return false;
//history.back();
}
</script>
<?php
}

?>



<form action="all.php" method="post" onsubmit="return myFunction()">

<div class="container">
<div id='fg_contact'>
<fieldset>
<legend>Contact Details</legend>

<input type="text" name="name" class="txt" placeholder="Full Name:" /><br/>
<input type="text" name="address" class="txt" placeholder="Address:" /><br/>
<input type="text" name="contact" class="txt" placeholder="Contact Number:" /><br/>
<input type="text" name="email" class="txt" placeholder="Email Address:" /><br/>
</fieldset>
</div>
<br/>

<div id='fg_reservation'>
<fieldset>
<legend>Reservation Details</legend>

<p>
<label for="password">Date</label><br/>
<input name="reserve" type="text" class="tcal txt-reg" id="fgh"/>
</p>
<br/><br/>

<table class="table-res">
<td class="table-td">

<select class="txt-reg" name="users" onchange="showUser(this.value)">
<option >Select a time:</option>
<option value="1">DayTime</option>
<option value="2">NightTime</option>
<option value="3">OverNight</option>
</select>
<br>
<div id="txtHint"><b>Person info will be listed here.</b></div>
<br/>


<select class="txt-reg" name="Cot" onchange="showCottage(this.value)">
<option >Select a cottage:</option>
<option value="4">Cottage1</option>
<option value="5">Cottage2</option>
<option value="6">Cottage3</option>
<option value="7">Cottage4</option>
<option value="8">Cottage5</option>
<option value="9">Cottage6</option>

<option value="10">Cottage7</option>
<option value="11">Cottage8</option>
<option value="12">Cottage9</option>
<option value="13">Cottage10</option>
<option value="14">Cottage11</option>
<option value="15">Cottage12</option>

<option value="16">Cottage14</option>
<option value="17">Cottage15</option>
<option value="18">Cottage16</option>
<option value="19">Cottage17</option>
<option value="20">Cottage18</option>
<option value="21">Cottage19</option>

<option value="22">Cottage20</option>
<option value="23">Cottage21</option>
<option value="24">Cottage22</option>
<option value="25">Cottage23</option>
<option value="26">Cottage24</option>
<option value="27">Cottage25</option>

<option value="28">Cottage26</option>
<option value="29">Cottage27</option>
<option value="30">Cottage28</option>
<option value="31">Cottage29</option>
<option value="32">Cottage30</option>
<option value="33">Cottage31</option>

<option value="34">Cottage32</option>
<option value="35">Cottage33</option>
<option value="36">Cottage34</option>
<option value="37">Cottage35</option>
<option value="38">Cottage36</option>
<option value="39">Cottage37</option>

<option value="40">Cottage38</option>
<option value="41">Cottage39</option>
<option value="42">Cottage40</option>
<option value="43">Cottage41</option>
</select>

<div id="txtcot"><b>Price of cottage will show here.</b></div>
<br/></td>

<td class="table-td">
Adult's Head Count :<br/>
<input type="text" class="txt-reg" name="headcount1" value="0" /><br/>
Children's Head Count :<br/>
<input type="text" class="txt-reg" name="headcount2" value="0" /><br/><br/>

<input type="submit" value="Calculate Discount" />
</td>
</table>
</fieldset>
</div>
</div>
</form>



</body>
</html>

最佳答案

像下面这样使用 strtotime() 函数:

if (strtotime($reserve) <= strtotime($currentDate))

代替

if ($reserve <= $currentDate)

关于javascript - 如何验证我的预订日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34409224/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com