Ich habe eine jquery Datepicker Eingabe in einem Formular. Es zeigt das aktuelle Datum korrekt als Anfangswert an. Ich möchte, dass dieser Datumswähler das Datum anzeigt, das ausgewählt wurde, als die Seite neu geladen wurde, nachdem das Formular abgeschickt wurde. Aber im Moment weiß ich nur, wie man das aktuelle Datum im value -Attribut wiedergibt. Hierdatepicker zeige ausgewählten Wert nach dem Formular reload
ist die picker Form in AppointmentDateSelector.php:
<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>
und Scheduling.php Seite, die es enthält.
<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>
Sie müssen das aufgenommene Datum in die Attributwert zu übergeben, sind vorbei Sie die aktuelle jedes Mal. –
Nachdem das Formular gesendet wurde, erhalten Sie den neuen Wert und Sie können den folgenden Code versuchen: var setDate = new Date ("Your Date Variable here"); setDate = $ .datepicker.formatDate ("yy-mm-dd", setDate); // ändere das Format bei Bedarf $ ("input.timepicker"). val (setDate); –
@VigneshVaidyanathan Wo sollte dieser Code eingefügt werden? – ArmorCode