Ask a Question related to Coldfusion - Getting Started, Design and Development.

  1. #1

    Default dateadd function

    I have 2 text field in a form.
    1st field for input date.
    I want to use onclick event handler for 2nd text field. When user click 2nd
    text field then show up the value of 10 days before the input date in 1st
    field. how do i do that?
    I try this:
    <input type="text" name="Balancedue"
    onclick="document.form.balancedue.value=dateadd("d ",-10,"document.form.eventdate
    ..value")">
    it doesnt work.
    thanks


    sweetyp2005 Guest

  2. Similar Questions and Discussions

    1. Facing problem in dateadd function.
      I am using dateadd function for "n" minutes but it is not working properly. Could someone tell me what is the problem in my code? <cfset...
    2. DateAdd function and Daylight savings
      The DateAdd and DateConvert functions are not working correctly when calculating a 2:00 am date/time on the morning of daylight savings. (This...
    3. DateAdd
      Hi, Here is my due date: end of the year + 40 working day. This is what I have but it gave me the wrong date ==================== <cfset yr=...
    4. dateadd()
      Hi! I need to add 1 day to a specific date. The date have is stored in a variable called "DateOld". The value of the variable have this syntax:...
    5. DateAdd does not work
      Dear Lord, I'm trying to code a drop down for a date entry that gives the user the option of the current date plus the dates of the last 7 days....
  3. #2

    Default Re: dateadd function

    I don't think there is a function called dateAdd() in Javascript.
    Is the following perhaps what you're looking for?




    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <html>
    <head>
    <title>Day of reckoning</title>
    </head>

    <body>
    <form>
    Event date: <input type="text" name="eventdate" value="10/27/2005"
    size="15">(MM/DD/YYYY)<br><br>
    <!--
    <input type="text" name="eventdate" value="27/10/2005" >(DD/MM/YYYY) <br>
    -->
    Balance due: <input type="text" name="Balancedue" value=""
    onclick="balanceDueDate(this.form,-10);" size="30">
    </form>

    <script language="JavaScript">
    <!--
    /* General remarks: In Javascript, month numbers run from 0(Jan) to 11(Dec),
    not from 1 to 12.
    The time interval, 'days', is an integer that may be positive (for a future
    date) or negative
    (for a date in the past) */
    function balanceDueDate(f,days) {
    try {
    var ed = f.eventdate.value;
    // With (MM/DD/YYYY) format
    var event_date = new
    Date(ed.substring(6,10),ed.substring(0,2)-1,ed.substring(3,5));
    // With (DD/MM/YYYY) format
    /*
    var event_date = new
    Date(ed.substring(6,10),ed.substring(3,5)-1,ed.substring(0,2));
    */
    var due_date = event_date.setDate(event_date.getDate() + days);
    f.Balancedue.value = (new Date(due_date)).toLocaleDateString();
    } catch(e) {
    alert('The Eventdate field must contain a valid date.');
    }

    }
    //-->
    </script>
    </body>
    </html>

    BKBK Guest

  4. #3

    Default Re: dateadd function

    Do you mean the DateAdd function in Coldfusion ?
    Try this:
    Code:
    <input type="text" name="Balancedue"
    onclick="document.form.balancedue.value=<cfoutput>dateadd('d',-10,'document.form
    ..eventdate.value')</cfoutput>;">
    redevolve Guest

  5. #4

    Default Re: dateadd function

    Redevolve says:
    Do you mean the DateAdd function in Coldfusion ?
    No, Sweetyp2005 calls dateAdd() in Javascript. I don't believe such a function
    exists in Javascript, though it does in Coldfusion.

    Try this: etc.
    Even if that approach works, it admits of some danger. You're using server-side
    code directly on user-input, without any validation whatsoever. In the most
    obvious case, if the user fills a non-date in the form, a Coldfusion error
    will result. You can avoid that completely by transferring all the processing
    to the client, even including a validation for the date input. That is what I
    aimed for.

    BKBK Guest

  6. #5

    Default Re: dateadd function

    that works but how can i have it shown in dd/mm/yyyy format instead of string?
    sweetyp2005 Guest

  7. #6

    Default Re: dateadd function

    Using Javascript date-time functions. Given date_object,
    the_day = date_object.getDate()
    the_mnth = date_object.getMonth()
    the_yr = date_object.getYear()



    BKBK Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139