Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

cfinput question - javascript, DOM, etc.

New Here ,
Jun 10, 2010 Jun 10, 2010

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;
                }

TOPICS
Getting started
675
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 10, 2010 Jun 10, 2010

The subject line suggests that there is a question but the OP does not include one.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 10, 2010 Jun 10, 2010

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 10, 2010 Jun 10, 2010

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 10, 2010 Jun 10, 2010

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 10, 2010 Jun 10, 2010

Did you try onChange?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 10, 2010 Jun 10, 2010
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources