Thanks Sam and Kristinn - really excellent help and solutions - I
learnt a lot as well!
Regards,
Bruce
At 03:48 a.m. 17/02/2007, you wrote:
>I did something similar once, so I just made some changes this should work:
>
>$( function () {
> $("[EMAIL PROTECTED]").change( function() {
> var reg = /date(on|off)(\d+)/i;
> var ar = reg.exec($(this).attr("id")); //id=dateoff3 => ar =
>[dateoff3, off, 3]
> if (ar[1] == "on")
> $("#dateoff"+ar[2]).attr("value",
> addTheDate(this.value,7)); //add
>.change() to make it go through all the fields
> else
> $("#dateon"+(++ar[2])).attr("value",
> addTheDate(this.value,1));
>//add .change() to make it go through all the fields
> });
>});
>
>If you really want to do step three (should add some verification as
>to not overwrite fields the user has already entered in advance), you
>just check the comments in the code... adding change() to the end
>would trigger the change event and run the code for the new input box.
>
>Good luck
>Kristinn
>On 2/16/07, Sam Collett <[EMAIL PROTECTED]> wrote:
> > On 16/02/07, Bruce MacKay <[EMAIL PROTECTED]> wrote:
> > >
> > > Hi folks,
> > >
> > > I have a set of n paired text input boxes (date on; date off). Each is
> > > attached to Kelvin Luck's date picker plugin.
> > >
> > > In most instances, the "date off" will be 7 days after the
> "date on", and
> > > the next "date on" will be 1 day after the preceding "date off".
> > >
> > > So, to help the user (so that they don't have to select dates
> for all the
> > > pairs of inputs), I want to:
> > > 1. for a given pair, populate the "date off" text input with a
> date that is
> > > 7 days later than the one selected in the "date on" box
> > > 2. for the following pair, populate the "date on" input with a
> date that is
> > > 1 day later than that of the "date off" box (in step #1)
> > > 3. repeat step #1 and cascade this down through the rest of the pairs.
> > >
> > > So far I can do step #1. I can't do step #2 as I don't know how to link
> > > the changed value of dateoff0 to the function being called in the second
> > > line of the code below (i.e. what goes in xx)
> > >
> > > $('#dateon0').change(function() {if
> > >
> (this.value.length>0)$('#dateoff0').attr("value",addTheDate(this.value,7));});
> > > $('#dateoff0').xx(function() {if
> > >
> (this.value.length>0)$('#dateon1').attr("value",addTheDate(this.value,1));});
> > >
> > > And, of course, I can't do step 3 because I'm hard coding the dateon /
> > > dateoff ids - there must be a way to do a loop but I can't work that out
> > > either.
> > >
> > > For completeness, my date-adding function is below.
> > >
> > > I'd really appreciate some help in filling the blanks in my capability.
> > >
> > > Thanks,
> > >
> > > Bruce
> > >
> > >
> > >
> > > function addTheDate(ej,df){
> > > var ar=new Array();
> > > ar=ej.split('/');
> > > var myDate = new Date;
> > > myDate.setDate(ar[0]);
> > > myDate.setMonth(ar[1]);
> > > myDate.setFullYear(ar[2]);
> > > myDate.setDate(myDate.getDate()+df);
> > > var d = myDate.getDate();
> > > var m = myDate.getMonth();
> > > var y = myDate.getFullYear();
> > > var dmy = d + "/" + m + "/" + y;
> > > return dmy;
> > > }
> > >
> > > I'm at a loss on the xxx bit - how can I take the date that is
> entered into
> > > #dateon, add 7 days to it, and insert it into #dateoff?
> >
> > Try something like this (untested):
> >
> > var to = 5;
> > for(var i = 0; i < to; i++) {
> > $('#dateon' + i).change(function() {
> > if (this.value.length>0) {
> > $('#dateoff' +
> i).attr("value",addTheDate(this.value,7)).each(function() {
> > if (this.value.length>0) $('#dateon' + (i +
> > 1)).attr("value",addTheDate(this.value,1));
> > });
> > }
> > });
> > }
> >
> > _______________________________________________
> > jQuery mailing list
> > [email protected]
> > http://jquery.com/discuss/
> >
>
>_______________________________________________
>jQuery mailing list
>[email protected]
>http://jquery.com/discuss/
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/