majed majed - 9 months ago 21
HTML Question

how to get work schedule

I have a work schedule that is two-week length. I want to make Sempel html page
with a datapicker and three textboxs
textbox1 view selected DatePicker week No
textbox2 view selected DatePicker day name
textbox3 show selected DatePicker if I work that day or I'm off.
textbox3 has 14 different cases:
I got this code
but it does not work.
can you chek what's wrong?
thanks for the help



<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Datepicker - Format date</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script type="text/javascript" src="/scripts/jquery.ui.datepicker-it.js"></script>

<script>
$(function() {
var weekStart = new Date(2017, 1, 27);
var roster = ['work', 'off', 'off', 'work', 'work', 'work', 'work',
'off', 'work', 'work', 'work', 'off', 'off', 'work'];
$('#date').datepicker({minDate: weekStart, onSelect: function(dateStr) {
var date = $(this).datepicker('getDate');
var days = Math.floor((date.getTime() - weekStart.getTime()) / (24 * 60 * 60 * 1000));
var week = Math.floor(days / 7) % 2;
$('#week').text(week + 1);
$('#day').text($.datepicker.formatDate('DD', date));
$('#work').text(roster[week * 7 + date.getDay() - 1]);
}});
});
</script>
</head>
<body>

<p>Date: <input type="text" id="date"></p>
<p>Day: <input type="text" id="day"></p>
<p>week: <input type="text" id="week"></p>
<p>work: <input type="text" id="work"></p>

</body>
</html>




Answer Source

You need to use val() to fill input boxes.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Datepicker - Format date</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script type="text/javascript" src="/scripts/jquery.ui.datepicker-it.js"></script>

<script>
$(function() {
  var weekStart = new Date(2017, 1, 27);
  var roster = ['work', 'off', 'off', 'work', 'work', 'work', 'work',
  	'off', 'work', 'work', 'work', 'off', 'off', 'work'];
  $('#date').datepicker({minDate: weekStart, onSelect: function(dateStr) {
    var date = $(this).datepicker('getDate');
    var days = Math.floor((date.getTime() - weekStart.getTime()) / (24 * 60 * 60 * 1000));
    var week = Math.floor(days / 7) % 2;
    $('#week').val(week + 1);
    $('#day').val($.datepicker.formatDate('DD', date));
    $('#work').val(roster[week * 7 + date.getDay() - 1]);
  }});
});
</script>
</head>
<body>
 
<p>Date: <input type="text" id="date"></p>
<p>Day: <input type="text" id="day"></p>
<p>week: <input type="text" id="week"></p>
<p>work: <input type="text" id="work"></p>

</body>
</html>