M
MC
This is a simple date picker. On changing the month or year, it should focus
on the next element. It does not do that because I am not referencing the
element correctly. See the line: this.dtDay.focus(); -->Problem this.dtDay
equals undefined
Resolution?
Thanks,
MC
PS, full text is included in case anyone wants to use it, or abuse it.
com.my.js.Month =
['January','February','March','April','May','June','July','August','September','October','November','December'];
com.my.js.DatePicker = function(startYr, endYr) {
this.dt = document.createElement("div");
this.dtMonth = document.createElement("select");
for (var i=0; i<com.aisus.js.Month.length; i++)
this.dtMonth.options = new Option(com.aisus.js.Month,i);
this.dtDay = document.createElement("select");
for (var i=0; i<32; i++)
this.dtDay.options = new Option(''+(i+1),(i+1));
this.dtYear = document.createElement("select");
this.dtYear.options[0] = new Option('',0);
for (var i=0; (startYr+i)<=(endYr); i++)
this.dtYear.options[i+1] = new Option(''+(endYr-i),(endYr-i));
this.dt.appendChild(this.dtMonth);
this.dt.appendChild(this.dtDay);
this.dt.appendChild(this.dtYear);
this.dtMonth.onchange = function(){
this.dtDay.focus(); -->Problem this.dtDay equals undefined
}
this.dtDay.onchange = function(){
this.dtYear.focus(); -->Problem this.dtYear equals undefined
}
};
com.my.js.DatePicker.prototype = {
getDiv: function() {return this.dt;},
getMonth: function() {return this.dtMonth.value;},
getDay: function() {return this.dtDay.value;},
getYear: function() {return this.dtYear.value;},
getMMDDYYYY: function() {
var s = '';
if (this.getMonth() < 9) s += '0';
s += ''+(parseInt(this.getMonth(), 10) + 1);
if (this.getDay() < 10) s += '0';
s += this.getDay();
s += this.getYear();
return s;
}
};
//Sample Usage
//var e = document.getElementById('someHtmlElementId');
//var datePicker = new com.aisus.js.DatePicker(1900,2011);
//e.appendChild(datePicker.getDiv());
on the next element. It does not do that because I am not referencing the
element correctly. See the line: this.dtDay.focus(); -->Problem this.dtDay
equals undefined
Resolution?
Thanks,
MC
PS, full text is included in case anyone wants to use it, or abuse it.
com.my.js.Month =
['January','February','March','April','May','June','July','August','September','October','November','December'];
com.my.js.DatePicker = function(startYr, endYr) {
this.dt = document.createElement("div");
this.dtMonth = document.createElement("select");
for (var i=0; i<com.aisus.js.Month.length; i++)
this.dtMonth.options = new Option(com.aisus.js.Month,i);
this.dtDay = document.createElement("select");
for (var i=0; i<32; i++)
this.dtDay.options = new Option(''+(i+1),(i+1));
this.dtYear = document.createElement("select");
this.dtYear.options[0] = new Option('',0);
for (var i=0; (startYr+i)<=(endYr); i++)
this.dtYear.options[i+1] = new Option(''+(endYr-i),(endYr-i));
this.dt.appendChild(this.dtMonth);
this.dt.appendChild(this.dtDay);
this.dt.appendChild(this.dtYear);
this.dtMonth.onchange = function(){
this.dtDay.focus(); -->Problem this.dtDay equals undefined
}
this.dtDay.onchange = function(){
this.dtYear.focus(); -->Problem this.dtYear equals undefined
}
};
com.my.js.DatePicker.prototype = {
getDiv: function() {return this.dt;},
getMonth: function() {return this.dtMonth.value;},
getDay: function() {return this.dtDay.value;},
getYear: function() {return this.dtYear.value;},
getMMDDYYYY: function() {
var s = '';
if (this.getMonth() < 9) s += '0';
s += ''+(parseInt(this.getMonth(), 10) + 1);
if (this.getDay() < 10) s += '0';
s += this.getDay();
s += this.getYear();
return s;
}
};
//Sample Usage
//var e = document.getElementById('someHtmlElementId');
//var datePicker = new com.aisus.js.DatePicker(1900,2011);
//e.appendChild(datePicker.getDiv());