Copy link to clipboard
Copied
Hi, I have a form which includes the following inputs:
<cfinput type="datefield"
id="startDate"
name="StartDate"
value="#StartDate#"
message="Start Date is required!"
required="yes"
validate="usdate"
validateat="onsubmit">
<cfinput type="datefield"
id="endDate"
name="EndDate"
value="#EndDate#"
message="End Date is required!"
required="yes"
validate="usdate"
validateat="onsubmit">
I've written a JavaScript function that listens to the startDate field and if modified, sets the endDate field to the same time:
<script type="text/javascript" language="javascript">
function populateEndDate(){
date = document.getElementById("startDate").value;
document.getElementById("endDate").value = date;
}
Copy link to clipboard
Copied
The subject line suggests that there is a question but the OP does not include one.
Copy link to clipboard
Copied
unfortunately, hit the wrong button and the post was submitted prematurely
was going to add:
My problem is in how to trigger the script when inputting the date using the cfCalendar date popup, which is the most convenient way to input the date. Does the DOM apply to cfInput fields, and if so, which DOM node would need to have an eventListener attached, and which event should be used? Any help would be appreciated.
Copy link to clipboard
Copied
Is there an html version of cfcalendar? I believe that when it came out it was flash only in which case js would not work.
Getting back to basic js, you need an event to trigger your function. I'd go with startdate onBlur myself.
Copy link to clipboard
Copied
Thanks Dan,
I tried onBlur already. The problem seems to be that when you use the date popup, although the input field gets populated with a valid date, it doesn't behave like you actually clicked in the field, or edited it, or left it. So if you use onBlur and enter a date using the popup, you need to also then click in the input field and then click elsewhere for onBlur to trigger, which is obviously not what I want.
So I figured that a better way to do it would be to attach an eventListener to the input field, which would theoretically be able to register any change that occurred in that field, whether it was from direct input or via the Date popup. But I'm stuck because I can't figure out exactly how to do this.
Copy link to clipboard
Copied
Did you try onChange?
Copy link to clipboard
Copied
Actually, that was the very first thing I tried followed by onBlur, etc. All those events don't seem to get triggered when you use the Date popup.