Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compare Dates 2

Status
Not open for further replies.

rmz8

Programmer
Aug 24, 2000
210
US
Is there any way to compare to dates in seperate form fields to make sure that one is later than the other?

Ryan ;-]
 
I coped it verbatim and it still doesn't work (w/o changing the operators).

Ryan ;-]
 
sorry works for me. What browser are you using? jared@aauser.com
 
8 posts up is a form and sample code...try that jared@aauser.com
 
hmm, I'm using IE5.5. What are you using? jared@aauser.com
 
Actually, that test code works. I just forgot to put the script in HEAD.

Ryan ;-]
 
Nevertheless, using an onclick while integrating it into my page doesn't work.

Ryan ;-]
 
In other words this doesn't work (making it onclick--but it must be because ColdFusion is already using onsubmit):

<script>
function todayDate(date, old)
{
var f = new Date(date);
var n = new Date(old);
if (f <= n)
{
return true

}
else
{

alert(&quot;Please enter an assigned date that is before the due date.&quot;);
return false;
}

}
</script>

<form name=&quot;formname&quot;>
<input name=&quot;AssignedDate&quot;>
<input name=&quot;DueDate&quot;>
<input type=&quot;submit&quot; onclick=&quot;return todayDate(document.formname.AssignedDate.value,document.formname.DueDate.value)&quot;>

But this does:

<script>
function todayDate(date, old)
{
var f = new Date(date);
var n = new Date(old);
if (f <= n)
{
return true

}
else
{

alert(&quot;Please enter an assigned date that is before the due date.&quot;);
return false;
}

}
</script>

<form name=&quot;formname&quot; onsubmit=&quot;return todayDate(document.formname.AssignedDate.value,document.formname.DueDate.value)&quot;>
<input name=&quot;AssignedDate&quot;>
<input name=&quot;DueDate&quot;>
<input type=&quot;submit&quot;>

Ryan ;-]
 
why are you using an onclick? use an onsubmit in the form tag adam@aauser.com
 
I just said--ColdFusion is already using OnSubmit for one of it's validation functions. I believe the problem lies within &quot;return&quot; before the onclick. When I remove it, it functions, although it continues to submit the form.

Ryan ;-]
 
<script>
function todayDate(date, old)
{
var f = new Date(date);
var n = new Date(old);
if (f <= n)
{
return true

}
else
{

alert(&quot;Please enter an assigned date that is before the due date.&quot;);
return false;
}

}
</script>

<form name=&quot;formname&quot;>
<input name=&quot;AssignedDate&quot;>
<input name=&quot;DueDate&quot;>
<input type=&quot;submit&quot; onclick=&quot;return todayDate(document.formname.AssignedDate.value,document.formname.DueDate.value)&quot;>


this worked in IE5.5 for me. adam@aauser.com
 
That doesn't work for me in IE 5.5 (it just submits the form with no alert). This is the exact HTML from the page:

<HTML>
<HEAD>
<TITLE>Untitled Document</TITLE>
<META HTTP-EQUIV=&quot;Content-Type&quot; CONTENT=&quot;text/html; charset=iso-8859-1&quot;>
<SCRIPT>
function todayDate(date, old)
{
var f = new Date(date);
var n = new Date(old);
if (f <= n)
{
return true

}
else
{

alert(&quot;Please enter an assigned date that is before the due date.&quot;);
return false;
}

}
</SCRIPT>
</HEAD>

<BODY BGCOLOR=&quot;#FFFFFF&quot;>

<FORM NAME=&quot;formname&quot;>
<INPUT NAME=&quot;AssignedDate&quot;>
<INPUT NAME=&quot;DueDate&quot;>
<INPUT TYPE=&quot;submit&quot; onClick=&quot;return todayDate(document.formname.AssignedDate.value,document.formname.DueDate.value)&quot; NAME=&quot;submit&quot;>
</FORM>
</BODY>
</HTML>

Ryan ;-]
 
How are you entering the dates? I use MM/DD/YY

Ryan ;-]
 
Ahh...I just tried it with MM/DD/YYYY and it functions. But I need it to work with the last two digits. Is that possible?

Ryan ;-]
 
hey, coldfusion doesn't use onsubmit
there is NO problem at all calling a jscript function in the onsubmit to validate inputs and do the treatments on the called page with coldfusion - usually it's the way people use it !!!!!
 
I'm using CFFORM, which uses OnSubmit. When I try to define an OnSubmit value in the CFFORM tag, I get a CF error. Anyway, I figured out that the code does indeed work for MM/DD/YYYY formatted dates, but I was entering MM/DD/YY dates. Is there anyway to make this function work with MM/DD/YY date formatting?

Ryan ;-]
 
function fixForRyan(str)
{
if(str.length<10)
{
return str.substring(0,6)+&quot;20&quot;+str.substring(6,str.length)
}
else{return str}
}

add this function somewhere, then change the old function to have:

var f = new Date(fixForRyan(date));
var n = new Date(fixForRyan(old));

i think this should work ( I hope!:)
jared@aauser.com
 
i find weird the way you do that ! it's not very logical !
either you use cfform, and then you should use coldfusion date validation/date comparaison functions, they are designed for that !!!
or you want to use javascript validation/comparaison functions, and then a simple <form> is better than a <cfform>

 
I won't use CF date comparison because I want it client side. I am already using CFFORM to ensure that the date is properly formatted. Prior to the date comparison my JavaScript knowledge didn't have to be that great--and that is why I chose CFFORM--considering that all I needed was one date comparison function. I didn't realize that problems that would arise--anyway, onClick should function just the same as onSubmit.

Ryan ;-]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top