[英]Typing the date time in textbox, does not change the selected value of date picker
[英]Change the value of the textbox when particular date is selected in php
當在輸入類型日期中選擇特定日期時,我想更改文本框的數量。當用戶點擊日期 11 月 2 日時,金額文本框應為 100 rs,而當點擊星期日時,金額為 500,其他金額為 300。 . 我該怎么做這是代碼
<script type="text/javascript">
$(function() {
$("#txtDate").change(function() {
var selDate = new Date(this.value);
if (selDate.getDay() == 0) { //If sunday, can change your logic here
$(".form-control").val(500);
} else {
$(".form-control").val(300);
}
})
});
</script>
<input type="date" name="mass_date" id="txtDate" required="required" class="col-md-12" min="<?php echo date('Y-m-d', strtotime("+2 days")); ?>" max="<?php echo date("Y-m-d", strtotime("2020-09-30"));?>" value="<?php if(isset($_GET['mass_date'])) { echo $_GET['mass_date']; } ?>" />
<input type="text" class="form-control" id="slDay" name="amount" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script type="text/javascript"> $(function() { $("#txtDate").change(function() { const selDate = new Date(this.value); const dayOfMonth = selDate.getDate(); const month = selDate.getMonth() + 1; const dayOfWeek = selDate.getDay(); if (month === 11 && dayOfMonth === 2) { $(".form-control").val(100); } else if (dayOfWeek === 0) { $(".form-control").val(500); } else { $(".form-control").val(300); } }) }); </script> <input type="date" name="mass_date" id="txtDate" required="required" class="col-md-12" min="<?php echo date('Ym-d', strtotime("+2 days")); ?>" max="<?php echo date("Ymd", strtotime("2020-09-30"));?>" value="<?php if(isset($_GET['mass_date'])) { echo $_GET['mass_date']; } ?>" /> <input type="text" class="form-control" id="slDay" name="amount" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.