[英]Dynamically display available months left in a select dropdown based on Year selected in another select dropdown
I have a table that has the months from January to December with values 1 to 12. On my page i have a dropdown with years from current year.我有一张表,其中包含从 1 月到 12 月的月份,值为 1 到 12。在我的页面上,我有一个从当年开始的年份的下拉列表。 I also have another dropdown that displays the months.
我还有另一个显示月份的下拉菜单。
By setting the current month, I can get the dropdown of months to display current month and the remaining month of the year.通过设置当前月份,我可以得到月份的下拉列表来显示当前月份和一年中剩余的月份。 What I need help for is for the month dropdown to display available months remaining based on year selected from the year dropdwon.
我需要帮助的是月份下拉菜单根据从 dropdwon 中选择的年份显示剩余的可用月份。 That is if I select 2019, I should see only December(current month and last month of year).
也就是说,如果我选择 2019,我应该只看到 12 月(当月和去年的最后一个月)。 If I pick 2020, I should see January to December.
如果我选择 2020 年,我应该会看到 1 月到 12 月。
I have checked other solutions, but it does not help with what I need.我已经检查了其他解决方案,但它对我所需要的没有帮助。 Some of the solutions seen have the month names as an array but the corresponding values are not included.
看到的一些解决方案将月份名称作为数组,但不包括相应的值。
My php code below:我的php代码如下:
$curmonth = date('n');
$query = "SELECT calmonthsID, months, value from calmonths WHERE value>=? ORDER BY calmonthsID ASC";
$stmt = $connQlife->prepare($query);
$stmt->bind_param('s', $curmonth);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($calmonthsID, $months, $value);
The html code below: html代码如下:
<select name="year" id="year" value="" tabindex="1" aria-hidden="true" required style="height:50px;display: block;padding:10px;" class="h5">
<option value="" selected="selected">- Select Year -</option>
<option value="2019">2019</option>
<option value="2020">2020</option>
<option value="2021">2021</option>
<option value="2022">2022</option>
</select>
<select name="month" id="month" value="" tabindex="1" aria-hidden="true" required style="height:50px;display: block;padding:10px;" class="h5">
<option value="" selected="selected">- Select One -</option>
<?php while($stmt->fetch()) { ?>
<option value=<?Php echo $value; ?>><?Php echo $months; ?></option>
<?php } $stmt->close(); ?>
</select>
If you don't want to use AJAX, I may suggest following workaround:如果您不想使用 AJAX,我可能会建议以下解决方法:
style.display:none
.style.display:none
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.