[英]Disable specific time in option if selected in <input type=date>
hello how can I disable the time from option tag when a certain date is selected in input date tag?您好,当在输入日期标签中选择某个日期时,如何禁用选项标签中的时间? Example is if 8:00 - 10:00 is taken on august 22, 2022, the option 8:00 - 10:00 is disabled on the same date and not on others.
例如,如果 2022 年 8 月 22 日采用 8:00 - 10:00,则选项 8:00 - 10:00 在同一日期禁用,而不是在其他日期禁用。 Here is the current code..
这是当前代码..
<label for="date">Date:</label>
<input type="date" name="date" id="date" min="<?php echo date("Y-m-d"); ?>" required/><br>
<label for="time">Choose an appointment time: </label><br>
<select name="time" id="time" ><br>
<?php
$sql2 = "SELECT * FROM time";
$result2 = $conn->query($sql2);
while($rows2=$result2->fetch_assoc())
{
<option value = "<?php echo $rows2['time']; ?>"><?php echo $rows2['time']; ?></option>
<?php
}
?>
</select>
Your code is selecting all time values from the database in one call rather than date specific.您的代码在一次调用中从数据库中选择所有时间值,而不是特定日期。
There's a lot of ways this could be tackled, for example,有很多方法可以解决这个问题,例如,
Here's an example for version 2 from another question that has a similar challenge.这是另一个具有类似挑战的问题的版本 2 示例。
Change <select> options with javascript dynamically 使用 javascript 动态更改 <select> 选项
It's worth noting, in their example the values are hardcoded, whereas in your case you'll need to dynamically create the javascript function.值得注意的是,在他们的示例中,这些值是硬编码的,而在您的情况下,您需要动态创建 javascript function。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.