Ask a Question related to Coldfusion - Getting Started, Design and Development.
-
sweetyp2005 #1
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
-
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... -
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... -
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=... -
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:... -
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.... -
BKBK #2
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
-
redevolve #3
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
-
BKBK #4
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
-
sweetyp2005 #5
Re: dateadd function
that works but how can i have it shown in dd/mm/yyyy format instead of string?
sweetyp2005 Guest
-
BKBK #6
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



Reply With Quote

