首先,我是PHP和JavaScript的新手。
我有多个输入框用于日期输入PHP。 我想要做的是如果用户根据输入的日期在第一个输入框中输入日期,当从第一个输入框(OnChange)离开时,其余的输入框应自动从SQL表(每周有一个日期)填满。
我对它怎么办都没有任何想法。 任何帮助将不胜感激.. 谢谢
我有输入框的代码
echo '<div class = "start_date" >'; //Start_Date class start
echo '<strong><label for="start_date">Start Date</label></strong>';
echo '<br/><br/>';
for($k=1;$k<=$textboxindex;$k++)
{
echo "<input type=\"text\" class='textboxsize' id= \"inputField$k\" name=\"start_date[]\" value=\"$start_date\" tabindex='$k'/>";
echo "<br/>";
}
echo '</div>'; //Start_date Class End
答案 0 :(得分:0)
您需要使用javascript运行ajax调用以预先填充其他选择框。
$('.date1').change(function() {
//prepopulate other select boxes
$.ajax({
url: 'ajax/date2.html',
success: function(data) {
$('.date2').html(data);
}
});
});
$('.date1').change(function() {
//prepopulate other select boxes
$.ajax({
url: 'ajax/date2.html',
success: function(data) {
$('.date2').html(data);
}
});
});
答案 1 :(得分:0)
$('.date1').change(function() {
//prepopulate other select boxes
var newDate = $(this).val();
var date = new Date(newDate);//if its not already a timestamp
var theday = date.getDate();
var themonth = date.getMonth()+1;
var theyear = date.getFullYear();
var nextDay = new Date(theyear+'-'+themonth+'-'+theday+1);//if its not already a timestamp
$('.date2').val(nextDay);
});
$('.date1').change(function() {
//prepopulate other select boxes
var newDate = $(this).val();
var date = new Date(newDate);//if its not already a timestamp
var theday = date.getDate();
var themonth = date.getMonth()+1;
var theyear = date.getFullYear();
var nextDay = new Date(theyear+'-'+themonth+'-'+theday+1);//if its not already a timestamp
$('.date2').val(nextDay);
});