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.
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:
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");
The 'success' forward goes to the calendar.jsp page, which generates the calendar with a custom tag.
The setDate() method is as follows:
function setDate(link, dateField)
fieldName = opener.document.getElementById(dateField);
fieldName.value = link.id;
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!