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

Updating a CF variable in Javascript

Status
Not open for further replies.

scripter73

Programmer
Joined
Apr 18, 2001
Messages
421
Location
US
Hi,

I REALLY hope this isn't information overload. I'll try to explain this
as clearly as I can.

I have a form that has the following info:
1) text fields to represent date parts
2) checkboxes that represent reports a user can view upon selecting; the report data
will be based on the date range the user provides

<form name=&quot;homedate&quot; action=&quot;date.cfm&quot; method=&quot;post&quot;
onSubmit=&quot;return CountChecks(this.form);return verify(this);>
<input type=&quot;text&quot; name=&quot;startmonth&quot; maxlength=2 size=3>
<input type=&quot;text&quot; name=&quot;startday&quot; maxlength=2 size=3>
<input type=&quot;text&quot; name=&quot;startyear&quot; maxlength=4 size=5>
<input type=&quot;text&quot; name=&quot;endmonth&quot; maxlength=2 size=3>
<input type=&quot;text&quot; name=&quot;endday&quot; maxlength=2 size=3>
<input type=&quot;text&quot; name=&quot;endyear&quot; maxlength=4 size=5>
<input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Submit&quot;>

</form>

When the user Submits this form, the action page is another page that processes
my form data to retrieve the reports. Also, when the user submits the forms,
I have a function called CountChecks() that simply limits the user to
one day's worth of data when more than one checkbox is selected. (This info is
irrelevant to my problem.)
Likewise, I have a Javascript validation function
verify() (Also irrelevant to my problem.)

GOAL: Cold Fusion needs the form variables from its own page to
perform some data manipulations such as when the dates the user entered are past
a certain date, etc.


At first, I tried to create a JS function and pass a CF variable to that function, but
couldn't update the CF variable.

Now, what I'm trying to do is submit the form to itself and pass the form fields
through the URL so that CF can access the url variables. I don't want to have to
leave this page to go to another page.

Here's what I have so far:


<script language=&quot;Javascript&quot;>
<!--
function SubmitForm(){
document.homedate.action=&quot;homepage.cfm&quot;; (homepage.cfm is name of page)
document.homedate.method=&quot;get&quot;;
document.homedate.submit();
}
// -->

</script>

<form name=&quot;homedate&quot; action=&quot;date.cfm&quot; method=&quot;post&quot;
onSubmit=&quot;SubmitForm();return CountChecks(this.form);return verify(this);>

..... INPUT FIELDS FROM ABOVE I reset the text fields
to the url values.
.....

</form>

I really don't have a problem, but my goal is to use the form variables in my Cold Fusion
to do a DateDiff on the form fields and popup a message to the user if the dates
are more than 120 days from today's date.

I'm not sure where to stick that date check logic in relation to my current code before
I return the form to the user.

I realize this is a really long post, but any help you can provide would be GREATLY
appreciated.

Thanks in advance,
scripter73




Change Your Thinking, Change Your Life.
 
Hey tleish,

I checked out that link and it looks pretty good.

I'm modifying the presentDate() function to do the following:
1) take the two dates the user entered and find the
date difference of the two date from today's date

Example: startdate - today's date and enddate - today's date

What I'm doing is passing the form elements into the presentDate function instead of passing the whole form.

I don't need the user to choose the nearest interval and the date difference will always be in days. Also, I don't need the form updated with the date difference, so everything now comes as alert boxes.

In my function, I find today's date using the new Date() function and the subsequent methods getMonth, getDate, getYear. My problem is that the date returned to me is 03/13/2002 and I need it to be 03/13/02. I don't think the getYear method has been updated for the 21st century. Therefore, its throwing my date difference off.


// The presentDate function is called on when you
// click on the button on the form.
function presentDate(sd,ed) {
var ierr = 1 ;
RightNow = new Date();
var mpo = RightNow.getMonth() + 1;

var year = RightNow.getYear();
var subyear = year.substring(2,2);
alert(&quot;Subyear is &quot; + subyear);

var today = mpo + &quot;/&quot; + RightNow.getDate() + &quot;/&quot; + RightNow.getYear();
// Verify whether the user wants to return only whole
// intervals or intervals rounded to the nearest number
// of interval.
var roundDays = true;

alert(&quot;Today is &quot; + today);
alert(&quot;Rounddays is:&quot; + roundDays);
alert(&quot;sd is: &quot; + sd);
alert(&quot;ed is: &quot; + ed);

// Verify that the user entered something in the
// Start Date input box.
if(sd != '') {
if(!isNaN(Date.parse( sd ))) {
var s = new Date(Date.parse(sd)) ;
ierr = 0 ;
}
}

// Verify that the user entered something in the
// Ending Date input box.
if(ed != '' && ierr != 1) {
if(!isNaN(Date.parse( ed ))) {
var e = new Date(Date.parse(ed)) ;

// call the dateDiff function.
var tempa = suycDateDiff( s, today, &quot;d&quot;, roundDays ) ;
var tempb = suycDateDiff( e, today, &quot;d&quot;, roundDays ) ;
}else{
ierr = 1;
}
}else{
ierr = 1;
}

// update the tellTime field with our new value.
//MANIPULATE THE DIFFERENCE IN DAYS
alert(&quot;Today is again &quot; + today);
if ( tempa != null && ierr != 1 ) alert(&quot;The difference in days for first date/today is: &quot; + tempa);
if ( tempb != null && ierr != 1 ) alert(&quot;The difference in days for second date/today is: &quot; + tempb);

}


Here's a copy of my function. Right now I'm trying to do a substring of the Year, which I don't think you can do with a Date.

Any help you can provide is appreciated.

Thanks,
scripter73

Change Your Thinking, Change Your Life.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top