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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Another Use of CF code in Javascript

Status
Not open for further replies.

scripter73

Programmer
Apr 18, 2001
421
US
Hi,

I want to use the CF function IsDate() in a Javascript.
IsDate() should accept a dynamic JS date variable.

Here's what I have:


<head>
<title>Untitled</title>

<script>
//declare global variables to pass back to CF
var date1;
var date2;

function todayDate(date, old)
{
var f = new Date(date);
var n = new Date(old);

//populate global JS vars with dates
date1 = f;
date2 = n;

if ((f > n))
{
alert(&quot;Good date.&quot;);
}
else
{
alert(&quot;Bad date.&quot;);;
}

}

todayDate(&quot;01/02/2000&quot;, &quot;01/01/2001&quot;);

//verify the date is valid
var verifyvalue = &quot;<cfoutput>#IsDate(01/01/2001)#</cfoutput>&quot;;
alert (&quot;Verify value is &quot; + verifyvalue);
</script>
</head>



IsDate() works fine when I hard-code a date, but if I say:

var verifyvalue = &quot;<cfoutput>#IsDate(f)#</cfoutput>&quot;;


I receive an error. Any ideas?

Any help's appreciated.

Thanks,
scripter73
Change Your Thinking, Change Your Life.
 
As far as I know, you can not access js variables with CF like you are trying to do. CF is server side and is looking for the value of f on the server side before the js can give it a value after reaching the client side.
If you are using this in a form, you could do the js validation of f<n with an onsubmit event then when the form action page is loaded do the date. Otherwise you could go a google.com search on &quot;javascript isdate()&quot; and find a ton of js date validators. The only dumb questions are the ones that are never asked
 
Just use this for example:

<cfoutput>
<script>
var verifyvalue = '#IsDate(DE(FORM.f))#';
</script>
</cfoutput>

IsDate is asking for a String so u can use DE(), or Evaluate(), that depends on what sort off variable f is.

give it a try.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top