Board Logo

update database after selecting date
jgc - 4/3/2011 at 05:31 AM

if you have an onChange event handler on the text box associated with the calendar (e.g., to save the selected date in a database) you will find that inserting the date in the text box with the calendar won't fire the event.

But you can call the handler in the calendar script (calendar_us.js)

Look in the script for this section (it's where the script writes the selected date to the associated text box):

function f_tcalHide (n_date) {
if (n_date)
this.e_input.value = this.f_generDate(new Date(n_date));

and add your code at the end of this function.

For example, I changed the code at the beginning of the function to this:

function f_tcalHide (n_date) {
var newdate = 0;
if (n_date) {
newdate = this.f_generDate(new Date(n_date));
this.e_input.value = newdate;
}

and then, at the end of the function, added something like this:

if (newdate != 0)
if (document.frmFormname)
updateTablename('displayname',this.e_input.id,recordid,'fieldname',newdate);

Here this.e_input.id is the id of the div containing the calendar-associated text box, and newdate is of course the date the user selected using the calendar. frmFormname is the form the calendar text box is in and UpdateTablename is a Javascript function that calls a php page to update a record in a database table using AJAX. But it could be any processing that you need to do with the selected date, including code that limits selected dates to future dates.

(the forum doesn't show it but I do indent the contents of ifs.)


Softcomplex: http://www.softcomplex.com/
Back to forum: http://www.softcomplex.com/forum/