32 lines
967 B
JavaScript
32 lines
967 B
JavaScript
/* $Id$ */
|
|
|
|
/**
|
|
* Update data in input elements for date by shifting it by @p days days.
|
|
*
|
|
* @param prefix Common prefix in input names, e.g. 'diary:edit:ddate'
|
|
* @param days Size of value shift, in days
|
|
*/
|
|
function change_date(prefix, days) {
|
|
var d = document.getElementsByName(prefix + ':day')[0];
|
|
var m = document.getElementsByName(prefix + ':month')[0];
|
|
var y = document.getElementsByName(prefix + ':year')[0];
|
|
var z = new Date(y.value, m.value - 1, d.value);
|
|
z.setTime(z.getTime() + 86400000 * days);
|
|
d.value = z.getDate();
|
|
m.value = z.getMonth() + 1;
|
|
y.value = z.getFullYear();
|
|
}
|
|
|
|
document.addEventListener('keypress', logKey);
|
|
|
|
function logKey(e) {
|
|
if (e.ctrlKey && e.keyCode == 10) {
|
|
var target = e.target
|
|
if (target.form)
|
|
target.form.submit()
|
|
} else if (e.ctrlKey && e.keyCode == 13) {
|
|
var target = e.target
|
|
if (target.form)
|
|
target.form.submit()
|
|
}
|
|
} |