简体   繁体   English

如果在选项中选择,则禁用特定时间选项<input type="date">

[英]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,有很多方法可以解决这个问题,例如,

  1. jQuery/AJAX - Used to fetch the times available based on the date selected jQuery/AJAX - 用于根据所选日期获取可用时间
  2. Javascript - Used to show only specific options once a date is selected Javascript - 用于在选择日期后仅显示特定选项
  3. Multi-Step Form - Ask for a date first, once submitted, then provide the times available多步骤表格 - 首先询问日期,一旦提交,然后提供可用的时间

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.

相关问题 Enable Disable specific date from input type=date 当日期存储在数据库中时 - Enable Disable specific date from input type=date when date stored in DB 如果不满足当前时间或日期,如何禁用选项 - How to disable option if current time or date is not met 禁用输入类型为“ date”的回溯日期条目 - Disable back date entries in input type 'date' 我们如何禁用 input type=&quot;date&quot; 中的 dd-mm-yyyy 字段,以便只能接受选定的日期 - how can we disable dd-mm-yyyy field in input type="date" so that only selected date can be accepted 禁用一个<option>当已经选择 - Disable an <option> when already selected 以HTML输入类型显示当前日期时间 - Show Current Date Time in HTML Input Type 禁用日期 <input type=“date”> 从数据库中的记录 - Disable the dates in <input type=“date”> from the records in the database 如何在选择将来的日期时禁用HTML日期输入类型? - How to disable html date input type in choosing future dates? 在循环中为该选择器的所有实例选择(在任何选择器中)特定选项后,暂时禁用该选项 - Temporarily disable a specific option after it has been selected (in any selector) for all instances of that selector in a loop 如何使用将选定的图像保存在特定文件夹中<input type="file"> - How to save selected image in specific folder using <input type="file">
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM