logo

New Response

« Return to the main article

You are replying to:

  1. Mr Paynter,

    I take it this means you have a job then?

    You won't be able to do it this way as, as it stands, you are trying to compare two *strings*. You need to convert them both to JS time/date objects first. Here's a function that should work:

    [<code>]function checkDateFollows( dp1, up1 ){

    dp1 = frm.FieldA.value; up1 = frm.FieldB.value;

    ds1 = dp1.split('/'); ds2 = up1.split('/');

    d1 = new Date(); d2 = new Date(); d1.setFullYear(parseInt(ds1[2],10)); d1.setMonth(parseInt(ds1[1],10)-1); d1.setDate(parseInt(ds1[0],10)); d1.setHours(0); d1.setMinutes(0);

    d2.setFullYear(parseInt(ds2[2],10)); d2.setMonth(parseInt(ds2[1],10)-1); d2.setDate(parseInt(ds2[0],10)); d2.setHours(0); d2.setMinutes(0);

    return ( d1.getTime() <= d2.getTime() ); }[</code>]

    Which you would call from anywhere in your script like so:

    [<code>]if ( checkDateFollows( f.DateA.value, f.DateB.value) ) { alert("The Date B can't be before Date A"); f.DateB.focus(); return false }[</code>]

    See you soon, Jake

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment: