Need a little help :)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Keyed4U

    #1

    Need a little help :)

    I have a drop down list system (works to some extent) for a date range search
    that I need to do a little more. The following is a small sample from the
    script:

    function modify_mo_list( mo_model)
    {
    molist = document.forms[0].querymo2;
    if (mo_model == '/01/') {
    var i = 0;
    molist.options[i++] = new Option('Februar y','/02/');
    molist.options[i++] = new Option('March', '/03/');
    molist.options[i++] = new Option('April', '/04/');
    molist.options[i++] = new Option('May','/05/');
    molist.options[i++] = new Option('June','/06/');
    molist.options[i++] = new Option('July','/07/');
    molist.options[i++] = new Option('August' ,'/08/');
    molist.options[i++] = new Option('Septemb er','/09/');
    molist.options[i++] = new Option('October ','/10/');
    molist.options[i++] = new Option('Novembe r','/11/');
    molist.options[i++] = new Option('Decembe r','/12/');
    molist.options[i++] = new Option('January ','/01/');
    molist.options. length = i;
    }
    }

    The entire list is comprised of Months Jan-Dec and years 1990-2006. I have it
    automatically selecting the next month, when the user selects June in the first
    box it automatically changes the second box to July. The year also when changed
    updates the next year box. But what I also need is for the year to advance 1
    year if December is selected, so that the search is from December 2000 to
    January 2001. Right now it will display December 2000 to January 2000. However
    when the actual searching takes place in my cgi it searches based on the input,
    having those dates as input it will actually search and print everything it
    finds except what is between those dates as it is looking for greater than
    December 2000 and less than January 2000.

    So basically I need it to change the date as it does for all months other than
    December, where it is to change the year to the next year.

    I have tried so many things to no avail. If someone has a suggestion let me
    know.

    You can view a working sample here:
    <a href="http://www.inspiration aldistributors. com/search4date.htm l">

    </a> You should also be able to see the source code for how it works there also
    so you can see all the code involved.

    Thanks for any help

    Jeff C
  • Ivo

    #2
    Re: Need a little help :)


    "Keyed4U" <keyed4u@aol.co m> wrote in message
    news:2003092622 3434.14379.0000 0185@mb-m15.aol.com...[color=blue]
    > I have a drop down list system (works to some extent) for a date range[/color]
    search
    I have it[color=blue]
    > automatically selecting the next month, when the user selects June in the[/color]
    first[color=blue]
    > box it automatically changes the second box to July. The year also when[/color]
    changed[color=blue]
    > updates the next year box. But what I also need is for the year to advance[/color]
    1[color=blue]
    > year if December is selected, so that the search is from December 2000 to
    > January 2001. Right now it will display December 2000 to January 2000.
    > You can view a working sample here:
    > http://www.inspirationaldistributors...arch4date.html
    > Thanks for any help
    > Jeff C[/color]

    I was just working on some PHP script which does the same also for days,
    given an array $getDaysInMonth (31,28/29,31,30,31,etc .). See if you can
    convert it to javascript:

    function adjustDate($day ,$month, $year) {
    $a = array($day,$mon th,$year);
    while ($a[0] > getDaysInMonth( $a[1], $a[2])) {$a[0] -=
    getDaysInMonth( $a[1], $a[2]); $a[1]++;while ($a[1] > 12) { $a[1] -= 12;
    $a[2]++;}}
    while ($a[0] <= 0) { $a[0] += getDaysInMonth( $month, $year); $a[1]--; while
    ($a[1] <= 0) { $a[1] += 12; $a[2]--; }}
    while ($a[1] > 12) { $a[1] -= 12; $a[2]++; }
    while ($a[1] <= 0) { $a[1] += 12; $a[2]--; }
    return $a;
    }


    Comment

    • Ivo

      #3
      Re: Need a little help :)


      "Ivo" <no@thank.you > wrote in message
      news:3f7511bf$0 $426$1b62eedf@n ews.wanadoo.nl. ..[color=blue]
      >
      > "Keyed4U" <keyed4u@aol.co m> wrote in message
      > news:2003092622 3434.14379.0000 0185@mb-m15.aol.com...[color=green]
      > > I have a drop down list system (works to some extent) for a date range[/color]
      > search
      > I have it[color=green]
      > > automatically selecting the next month, when the user selects June in[/color][/color]
      the[color=blue]
      > first[color=green]
      > > box it automatically changes the second box to July. The year also when[/color]
      > changed[color=green]
      > > updates the next year box. But what I also need is for the year to[/color][/color]
      advance[color=blue]
      > 1[color=green]
      > > year if December is selected, so that the search is from December 2000[/color][/color]
      to[color=blue][color=green]
      > > January 2001. Right now it will display December 2000 to January 2000.
      > > You can view a working sample here:
      > > http://www.inspirationaldistributors...arch4date.html
      > > Thanks for any help
      > > Jeff C[/color]
      >
      > I was just working on some PHP script which does the same also for days,
      > given an array $getDaysInMonth (31,28/29,31,30,31,etc .). See if you can
      > convert it to javascript:
      >
      > function adjustDate($day ,$month, $year) {
      > $a = array($day,$mon th,$year);
      > while ($a[0] > getDaysInMonth( $a[1], $a[2])) {
      > $a[0] -= getDaysInMonth( $a[1], $a[2]);
      > $a[1]++;while ($a[1] > 12) { $a[1] -= 12; $a[2]++;}
      > }
      > while ($a[0] <= 0) {
      > $a[0] += getDaysInMonth( $month, $year);
      > $a[1]--; while ($a[1] <= 0) { $a[1] += 12; $a[2]--; }
      > }
      > while ($a[1] > 12) { $a[1] -= 12; $a[2]++; }
      > while ($a[1] <= 0) { $a[1] += 12; $a[2]--; }
      > return $a;
      > }[/color]

      Went too fast. getDaysInMonth is a function that considers the year in its
      second argument, so that we can determine February.
      HTH
      I


      Comment

      • Lee

        #4
        Re: Need a little help :)

        Keyed4U said:[color=blue]
        >
        >I have a drop down list system (works to some extent) for a date range search
        >that I need to do a little more. The following is a small sample from the
        >script:[/color]

        Let the built-in Date() object do the calculations for you:


        <html>
        <head>
        <script type="text/javascript">
        function update(f){
        if(f.m0.selecte dIndex && f.y0.selectedIn dex){
        m0=f.m0.selecte dIndex;
        y0=1989+f.y0.se lectedIndex;
        date1=new Date(y0,m0,1);
        f.m1.selectedIn dex=date1.getMo nth()+1;
        f.y1.selectedIn dex=date1.getFu llYear()-1989;
        }
        }
        </script>
        </head>
        <body>
        <form>
        <select name="m0" onchange="updat e(this.form)">
        <option>Choos e Month</option>
        <option>January </option>
        <option>Februar y</option>
        <option>March </option>
        <option>April </option>
        <option>May</option>
        <option>June</option>
        <option>July</option>
        <option>Augus t</option>
        <option>Septemb er</option>
        <option>October </option>
        <option>Novembe r</option>
        <option>Decembe r</option>
        </select>
        <select name="y0" onchange="updat e(this.form)">
        <option>Choos e Year</option>
        <option>1990</option>
        <option>1991</option>
        <option>1992</option>
        <option>1993</option>
        <option>1994</option>
        <option>1995</option>
        <option>1996</option>
        <option>1997</option>
        <option>1998</option>
        <option>1999</option>
        <option>2000</option>
        <option>2001</option>
        <option>2002</option>
        <option>2003</option>
        <option>2004</option>
        <option>2005</option>
        <option>2006</option>
        </select>
        <br>
        <select name="m1">
        <option>Choos e Month</option>
        <option>January </option>
        <option>Februar y</option>
        <option>March </option>
        <option>April </option>
        <option>May</option>
        <option>June</option>
        <option>July</option>
        <option>Augus t</option>
        <option>Septemb er</option>
        <option>October </option>
        <option>Novembe r</option>
        <option>Decembe r</option>
        </select>
        <select name="y1">
        <option>Choos e Year</option>
        <option>1990</option>
        <option>1991</option>
        <option>1992</option>
        <option>1993</option>
        <option>1994</option>
        <option>1995</option>
        <option>1996</option>
        <option>1997</option>
        <option>1998</option>
        <option>1999</option>
        <option>2000</option>
        <option>2001</option>
        <option>2002</option>
        <option>2003</option>
        <option>2004</option>
        <option>2005</option>
        <option>2006</option>
        <option>2007</option>
        </select>
        </form>
        </body>
        </html>

        Comment

        • Keyed4U

          #5
          Re: Need a little help :)

          Thanks for the help, it seems that the built-in date function does in deed work
          perfect. Again it was much appreciated. I usually stick to cgi, but for this
          small project I wanted to reduce the number of scripts in the cgi directory for
          me to have to keep track of!!

          Jeff C

          Comment

          • Dr John Stockton

            #6
            Re: Need a little help :)

            JRS: In article <20030926223434 .14379.00000185 @mb-m15.aol.com>, seen in
            news:comp.lang. javascript, Keyed4U <keyed4u@aol.co m> posted at Sat, 27
            Sep 2003 02:34:34 :-

            Please use an informative Subject line.
            [color=blue]
            >So basically I need it to change the date as it does for all months other than
            >December, where it is to change the year to the next year.[/color]

            with (DateObj) setMonth(getMon th()+1) // can use UTC.
            [color=blue]
            >I have tried so many things to no avail. If someone has a suggestion let me
            >know.[/color]

            The FAQ? see below.
            [color=blue]
            >You can view a working sample here:[/color]

            Not helpful to those who read News off-line. A clear and unambiguous
            description of the need is better.

            --
            © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
            <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
            <URL:http://www.merlyn.demo n.co.uk/js-index.htm> JS maths, dates, sources.
            <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.

            Comment

            • Keyed4U

              #7
              Re: Need a little help :)

              Thanks to those who were actually helpful, and not to those that just can't
              help or explain, but rather complain about how a post is written. If you can't
              help out on the newsgroup posts, just don't bother commenting.

              Again thanks to the folks who DID give sample code and helpful information.

              Comment

              • Lasse Reichstein Nielsen

                #8
                Re: Need a little help :)

                keyed4u@aol.com (Keyed4U) writes:
                [color=blue]
                > Thanks to those who were actually helpful, and not to those that
                > just can't help or explain, but rather complain about how a post is
                > written. If you can't help out on the newsgroup posts, just don't
                > bother commenting.[/color]

                Sorry, but that attitude will not help get you answers from people who
                can help you.

                The suggestions on how to post are, to quote Matrix, for your
                protection. Following them will make it more likely that you get the
                help you need.

                /L
                --
                Lasse Reichstein Nielsen - lrn@hotpop.com
                Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
                'Faith without judgement merely degrades the spirit divine.'

                Comment

                Working...