Re: some javascript(+php) help needed

by "Srinivasan Ramakrishnan" <srinivar(at)md3.vsnl.net.in>

 Date:  Sat, 18 Nov 2000 02:30:40 +0530
 To:  "Siim Einfeldt aka Itpunk" <siim_e(at)pshg.edu.ee>
 Cc:  <hwg-languages(at)hwg.org>
 References: 
  todo: View Thread, Original
Hi Siim,

Ok, here's what I'd do: (I'm not writing code since I'm a bit short of time,
maybe someone on the list can help you with that.)

Step1: I'd create a date object in JS based on the first selection.

A date object is of the form
startDate = new Date("October 02, 2000");

So first you make the date string from the 3 select boxes by getting the
month, day and year using

selectboxName.options[selectboxName.selectedIndex].text or
selectboxName.options[selectboxName.selectedIndex].value

Step2: Construct a similar date object when the 2nd select box is clicked

Step3: Check if the startDate is lesser than the endDate

If yes all OK else you alert the user.

Set all the date checking on the onChange event. After a bad date error
alert, set the date select boxes to the starting value, which would be I
guess a message like "Select a Month" which you have as the first element in
the month select box.

Now the user has to again change his selection to a valid one.


Extra:
------

As far as filling in the same info. in the 2nd box, if you mean the same
date, sure:

Do this, get the date values from the first select box and loop thru the 2nd
set of select boxes until the text/value is the same, now set this index as
the selected index.

Now if you want only dates after the start date to be in the 2nd box that
could be done too.

Let's say you have a max time of one month for the contract, now find the
date object of the first set of select boxes then add one month to it using


endDate = startDate;
endDate.setMonth(startDate.getMonth + 1)

You will have to get over the December problem here, since January will be
in the next month so add a check for that and add one year to it if that is
true.

If you hate this, and you prefer the down and dirty method of adding
seconds, you have to add

60*60*24*[28/30/31]...... based on the month.

You can see why I prefer the earlier method!!


Now extract the date string out of this by splitting the spaces and you get
three values of day, month and year. Now as before search the select boxes
for the same value, find its index, and set the selectedIndex property of
that selectbox to it.



-Srini







----- Original Message -----
From: Siim Einfeldt aka Itpunk <siim_e(at)pshg.edu.ee>
To: Srinivasan Ramakrishnan <srinivar(at)md3.vsnl.net.in>
Sent: Saturday, November 18, 2000 1:35 AM
Subject: Re: some javascript(+php) help needed


>
> > P.S: I mean this part::
> > -----------------------
> > > What I need, is when dateone has been selected (in other words, none
of
> > > the columns are ''), then datetwo fields would be given (shown)
exactly
> > > the same values. And now the most important part, when user starts to
> > > select datetwo now, then he shouldn�t have the possiblity to select
> > > earlier date that datetwo, that should be forbidden. As one is
actually
> > > contract start date and the second is contract end date,this is
important
> > > to get to work like that.
>
>    Ok, I`ll try to explain a bit better. There are two dates, one is
> contract start date, the other is contract end dates. Both these dates
> have been out to three select boxes(day-month-year). Now, when someone has
> already selected the start date of the contract, the end date select boxes
> should at first be filledwith the same information that was just entered
> to start date. Well, it would be good, if it was possible to do that as
> well, but  the most important thing: when the start date has been entered,
> there shouldn`t be any possiblity to put the contract end date earlier
> than start date. That`s the point. I hope you got it now. Letme know if
> you have some solution.
>
>
> Cheers
> Siim Einfeldt
>
>

HWG: hwg-languages mailing list archives, maintained by Webmasters @ IWA