フォームにjquery datepicker入力があります。現在の日付を初期値として正しく表示します。フォームを送信した後にページがリロードされたときに選択された日付をこのdatePickerに表示させたいと思います。しかし今、私はvalue属性に現在の日付をエコーする方法しか知りません。datepickerはフォームリロード後に選択した値を表示します
<form method="POST">
<div style='margin:0 auto; text-align:center;'>
<label>Appointment Date: </label>
<input type="text" id="datepicker" name="date" value=<?php echo date('m/d/Y');?> />
<input type="hidden" name="action" value="list_appointments"/>
<input type="hidden" name="date" value="Value of datepicker goes here?"/>
<input type="submit" value="Refresh List" name="Update" />
<br />
</div>
</form>
、それを含んScheduling.phpページ:ここ
はAppointmentDateSelector.phpでDatePickerのフォームです。あなたは日付が送信されたことかどうかをチェックし、その場合には、値としてそれを使用する必要が
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<!-- for datepicker -->
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.17/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.17/jquery-ui.min.js"></script>
<!-- for timepicker -->
<script src="//cdnjs.cloudflare.com/ajax/libs/timepicker/1.3.5/jquery.timepicker.min.js"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/timepicker/1.3.5/jquery.timepicker.min.css">
<script type="text/javascript">
$(document).ready(function(){
$("#datepicker").datepicker({minDate:'0',
beforeShowDay:
function(dt)
{
return [dt.getDay() === 2 || dt.getDay() === 3, ""];
}});
});
$(document).ready(function(){
$('input.timepicker').timepicker({
timeFormat: 'h:mm p',
interval: 30,
minTime: '9',
maxTime: '5:00pm',
defaultTime: '9',
startTime: '9:00',
dynamic: false,
dropdown: true,
scrollbar: true
});
});
</script>
</head>
<body>
<?php
include('AppointmentDateSelector.php');
// determine if we got a INPUT_POST or INPUT_GET...
// if both NULL, then should default to 'list_appointments'
$action = filter_input(INPUT_POST, 'action');
if ($action == NULL)
{
$action = filter_input(INPUT_GET, 'action');
if ($action == NULL) {
$action = 'list_appointments';
}
}
if ($action == 'list_appointments')
{
$date = filter_input(INPUT_POST, 'date');
$dateparse = date_parse($date);
#var_dump($dateparse);
if (checkdate($dateparse['month'], $dateparse['day'], $dateparse['year']))
{
// Get Appointment data
$appointments = get_appointments($date);
//header("Location: ./Scheduling.php?date=$date");
// displays list of appointments on that date
include('AppointmentList.php');
}
else
{
//Raise an error that says invalid date.
}
}
?>
</body>
</html>
あなたのvalue属性に選んだ日付を渡す必要がある、あなたは電流を流しています毎回。 –
フォームが送信された後、新しい値を取得し、次のコードを試すことができます:var setDate = new Date( "ここにあなたの日付変数"); setDate = $ .datepicker.formatDate( "yy-mm-dd"、setDate); //必要に応じて書式を変更します。 $( "input.timepicker")。val(setDate); –
@VigneshVaidyanathanそのコードはどこに挿入する必要がありますか? – ArmorCode