Hi all,

Some of you may have read my post a few days ago asking about the pop-up calendar idea. One of the users that responded to me suggested I share my solution with the community and get some constructive feedback. So, if you have a few minutes, please look this over and let me know if I'm doing this really badly - after all, this is how I learn.

-------------
For each date field on my main form, I have a text box containing the date. I set the onClick attribute to call a JavaScript function, selectDate(), which initiates the pop-up.
I have multiple date fields on the form, so I need to specify which date field should receive the date chosen by this popup calendar. So one of the parameters to selectDate() is the name of the date field:

<input type="text" name="startDate" size="15" onClick="selectDate('startDate')"/>

And here is the startDate() function:
function selectDate(dateField)
{
    var url = "selectDate.do?dateField=" + dateField;
    var options = "toolbar=0,location=0,left=200,top=200,width=200,height=200";

    window.open(url, "calendar", options);
}

Why am I using a Struts action? Later on, once I figure out my approach, I am adding other stuff - there are certain dates that have special attributes in my database and the Struts action will use Hibernate to look up those items.

So, basically, in the meantime, what the Struts action does is this, in the execute() method:

   String dateField = req.getParameter("dateField");
   req.setAttribute("dateField", dateField);

   return mapping.findForward("success");

The 'success' forward goes to the calendar.jsp page, which generates the calendar with a custom tag.

Basically, each day in the calendar has a link to another JavaScript function, setDate(), that has the <a> element and the field name. So, a day in the calendar might look like this:

<a id='20040927' href="#" onClick="javascript:setDate(this, 'startDate')">27</a>

The setDate() method is as follows:

function setDate(link, dateField)
{
    fieldName = opener.document.getElementById(dateField);
    fieldName.value = link.id;
    window.close();
}

So then, the date field in the opening page is set to the newly selected date.

What do you think? Is this reasonable well-done/efficient, or is it totally inefficient?

Thanks for taking the time to read this!

Joe