Auto insert Date in form input field

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

    Auto insert Date in form input field

    I just want to enter today's date in a text input box with the format
    mm/dd/yyyy when it receives focus. I've been playing around with this but
    just can't seem to get it to work.

    Any help would be appreciated.

    Doug


  • Lee

    #2
    Re: Auto insert Date in form input field

    Dwalker said:[color=blue]
    >
    >I just want to enter today's date in a text input box with the format
    >mm/dd/yyyy when it receives focus. I've been playing around with this but
    >just can't seem to get it to work.
    >[/color]

    <html>
    <head>
    <script type="text/javascript">
    function zp(n){
    return n<10?("0"+n):n ;
    }
    function insertDate(t,fo rmat){
    var now=new Date();
    var DD=zp(now.getDa te());
    var MM=zp(now.getMo nth()+1);
    var YYYY=now.getFul lYear();
    var YY=zp(now.getFu llYear()%100);
    format=format.r eplace(/DD/,DD);
    format=format.r eplace(/MM/,MM);
    format=format.r eplace(/YYYY/,YYYY);
    format=format.r eplace(/YY/,YY);
    t.value=format;
    }
    </script>
    </head>
    <body>
    <form>
    <input onfocus="insert Date(this,'MM/DD/YYYY')"><br>
    <input onfocus="insert Date(this,'MM/DD/YY')"><br>
    <input onfocus="insert Date(this,'DD/MM')"><br>
    <input onfocus="insert Date(this,'YYYY-MM-DD')"><br>
    </form>
    </body>
    </html>

    Comment

    • Dwalker

      #3
      That's a work of art - thank you! (nt)


      "Lee" <REM0VElbspamtr ap@cox.net> wrote in message
      news:bkvanj057i @drn.newsguy.co m...[color=blue]
      > Dwalker said:[color=green]
      > >
      > >I just want to enter today's date in a text input box with the format
      > >mm/dd/yyyy when it receives focus. I've been playing around with this but
      > >just can't seem to get it to work.
      > >[/color]
      >
      > <html>
      > <head>
      > <script type="text/javascript">
      > function zp(n){
      > return n<10?("0"+n):n ;
      > }
      > function insertDate(t,fo rmat){
      > var now=new Date();
      > var DD=zp(now.getDa te());
      > var MM=zp(now.getMo nth()+1);
      > var YYYY=now.getFul lYear();
      > var YY=zp(now.getFu llYear()%100);
      > format=format.r eplace(/DD/,DD);
      > format=format.r eplace(/MM/,MM);
      > format=format.r eplace(/YYYY/,YYYY);
      > format=format.r eplace(/YY/,YY);
      > t.value=format;
      > }
      > </script>
      > </head>
      > <body>
      > <form>
      > <input onfocus="insert Date(this,'MM/DD/YYYY')"><br>
      > <input onfocus="insert Date(this,'MM/DD/YY')"><br>
      > <input onfocus="insert Date(this,'DD/MM')"><br>
      > <input onfocus="insert Date(this,'YYYY-MM-DD')"><br>
      > </form>
      > </body>
      > </html>
      >[/color]


      Comment

      • Dr John Stockton

        #4
        Re: Auto insert Date in form input field

        JRS: In article <wRFcb.20144$jO .19590@bignews3 .bellsouth.net> , seen in
        news:comp.lang. javascript, Dwalker <dl_walker@hotm ail.com> posted at
        Thu, 25 Sep 2003 13:47:05 :-
        [color=blue]
        >I just want to enter today's date in a text input box with the format
        >mm/dd/yyyy when it receives focus. I've been playing around with this but
        >just can't seem to get it to work.[/color]

        That format should nor be used on the World-Wide Web; since only a few
        countries use it, it is generally misleading (as is dd/mm/yyyy, of
        course).

        --
        © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
        Web <URL:http://www.merlyn.demo n.co.uk/> - w. FAQish topics, links, acronyms
        PAS EXE etc : <URL:http://www.merlyn.demo n.co.uk/programs/> - see 00index.htm
        Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.

        Comment

        • Ivo

          #5
          Re: Auto insert Date in form input field


          "Dr John Stockton" <spam@merlyn.de mon.co.uk> wrote in message
          news:ro82WVGt+A d$Ewq6@merlyn.d emon.co.uk...[color=blue]
          > JRS: In article <wRFcb.20144$jO .19590@bignews3 .bellsouth.net> , seen in
          > news:comp.lang. javascript, Dwalker <dl_walker@hotm ail.com> posted at
          > Thu, 25 Sep 2003 13:47:05 :-
          >[color=green]
          > >I just want to enter today's date in a text input box with the format
          > >mm/dd/yyyy when it receives focus. I've been playing around with this but
          > >just can't seem to get it to work.[/color]
          >
          > That format should nor be used on the World-Wide Web; since only a few
          > countries use it, it is generally misleading (as is dd/mm/yyyy, of
          > course).[/color]

          Things became confusing only after the colonists in the New World went
          looking for an identity in spelling anomalies.
          No 'countries' that I know of use the format yyyy/mm/dd although that is the
          one which sorts alphabetically and chronologically simultaneously. Or would
          you suggest using the Julian Day Number?
          Ivo


          Comment

          • Lee

            #6
            Re: Auto insert Date in form input field

            Dr John Stockton said:[color=blue]
            >
            >JRS: In article <wRFcb.20144$jO .19590@bignews3 .bellsouth.net> , seen in
            >news:comp.lang .javascript, Dwalker <dl_walker@hotm ail.com> posted at
            >Thu, 25 Sep 2003 13:47:05 :-
            >[color=green]
            >>I just want to enter today's date in a text input box with the format
            >>mm/dd/yyyy when it receives focus. I've been playing around with this but
            >>just can't seem to get it to work.[/color]
            >
            >That format should nor be used on the World-Wide Web; since only a few
            >countries use it, it is generally misleading (as is dd/mm/yyyy, of
            >course).[/color]

            Curiosity: How widely accepted is yyyy-mm-dd out there in the Rest of
            The World? In addition to software development, I've been using it on
            bank drafts and forms for several months, but have never spotted it in
            the wild (USA-AZ).

            Comment

            • Dr John Stockton

              #7
              Re: Auto insert Date in form input field

              JRS: In article <bl1sru02aj2@dr n.newsguy.com>, seen in
              news:comp.lang. javascript, Lee <REM0VElbspamtr ap@cox.net> posted at Fri,
              26 Sep 2003 10:26:22 :-[color=blue]
              >Dr John Stockton said:[color=green]
              >>
              >>JRS: In article <wRFcb.20144$jO .19590@bignews3 .bellsouth.net> , seen in
              >>news:comp.lan g.javascript, Dwalker <dl_walker@hotm ail.com> posted at
              >>Thu, 25 Sep 2003 13:47:05 :-
              >>[color=darkred]
              >>>I just want to enter today's date in a text input box with the format
              >>>mm/dd/yyyy when it receives focus. I've been playing around with this but
              >>>just can't seem to get it to work.[/color]
              >>
              >>That format should nor be used on the World-Wide Web; since only a few
              >>countries use it, it is generally misleading (as is dd/mm/yyyy, of
              >>course).[/color]
              >
              >Curiosity: How widely accepted is yyyy-mm-dd out there in the Rest of
              >The World? In addition to software development, I've been using it on
              >bank drafts and forms for several months, but have never spotted it in
              >the wild (USA-AZ).[/color]

              It is, I have been lead to understand, a US Federal Standard.
              USA Standard: ANSI X3.30-1985(R1991), FIPS PUB 4-1, 4-2.
              if you indulge in foreign travel, it is also
              Canada: CAN/CSA-Z234.5-89. (Z234-4 ?)
              and many others.


              It matters not, however, how widely it is used, but how widely it is
              understood correctly.

              My Bank have remarked (audibly) on seeing it, but have understood it and
              accepted it without demur.

              A date in MM/DD/YYYY, such as Jan 4th, being written as 01/04/2004, will
              be understood throughout Europe as meaning April Fools Day. The date of
              Remembrance Sunday, written demotically in the UK as 09/11/2003, will be
              misunderstood by Americans.

              But everyone can understand 2004/04/11 as being the coming Easter
              Sunday, given an adequate 2004 diary.

              --
              © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
              Web <URL:http://www.merlyn.demo n.co.uk/> - w. FAQish topics, links, acronyms
              PAS EXE etc : <URL:http://www.merlyn.demo n.co.uk/programs/> - see 00index.htm
              Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.

              Comment

              • Dr John Stockton

                #8
                Re: Auto insert Date in form input field

                JRS: In article <3f747aca$0$427 $1b62eedf@news. wanadoo.nl>, seen in
                news:comp.lang. javascript, Ivo <no@thank.you > posted at Fri, 26 Sep 2003
                19:43:42 :-[color=blue]
                >
                >"Dr John Stockton" <spam@merlyn.de mon.co.uk> wrote in message
                >news:ro82WVGt+ Ad$Ewq6@merlyn. demon.co.uk...[color=green]
                >> JRS: In article <wRFcb.20144$jO .19590@bignews3 .bellsouth.net> , seen in
                >> news:comp.lang. javascript, Dwalker <dl_walker@hotm ail.com> posted at
                >> Thu, 25 Sep 2003 13:47:05 :-
                >>[color=darkred]
                >> >I just want to enter today's date in a text input box with the format
                >> >mm/dd/yyyy when it receives focus.[/color]
                >>
                >> That format should nor be used on the World-Wide Web; since only a few
                >> countries use it, it is generally misleading (as is dd/mm/yyyy, of
                >> course).[/color]
                >
                >Things became confusing only after the colonists in the New World went
                >looking for an identity in spelling anomalies.[/color]

                Any responsibility that the UK may have for this must be shared in part
                with the country that founded New Amsterdam. It is one thing, I
                suspect, for which the French need not be blamed.
                [color=blue]
                >No 'countries' that I know of use the format yyyy/mm/dd although that is the
                >one which sorts alphabetically and chronologically simultaneously.[/color]

                I believe Japan and China use it routinely. MSDOS 5 believes that YYYY-
                MM-DD is also used in French Canada, Hungary, Czechoslovakia, Sweden,
                Yugoslavia, Poland.
                [color=blue]
                > Or would
                >you suggest using the Julian Day Number?[/color]

                No, not least because the Julian Day Number does not define a Civil
                Date. Modified JD defines a UK Civil Date (ignoring Summer Time); and
                Chronological JD & CMJD define a civil date anywhere.

                For more, see via below.

                --
                © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
                Web <URL:http://www.merlyn.demo n.co.uk/> - w. FAQish topics, links, acronyms
                PAS EXE etc : <URL:http://www.merlyn.demo n.co.uk/programs/> - see 00index.htm
                Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.

                Comment

                • Evertjan.

                  #9
                  Re: Auto insert Date in form input field

                  Dr John Stockton wrote on 28 sep 2003 in comp.lang.javas cript:[color=blue]
                  > But everyone can understand 2004/04/11 as being the coming Easter
                  > Sunday, given an adequate 2004 diary.[/color]

                  In 2004 everywhere, but:

                  "The Orthodox Easter usually falls later than the Catholic Easter,
                  depending on when Passover is. The Russian Easter falls one week after
                  Passover."

                  Year 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010

                  Catholic 23/4 15/4 31/3 20/4 11/4 27/3 16/4 8/4 23/3 12/4 4/4
                  Orthodox 30/4 15/4 5/5 27/4 11/4 1/5 23/4 8/4 27/4 19/4 4/4


                  John, as a numbercruncher you will like this, I hope:

                  <http://www.assa.org.au/edm.html>



                  --
                  Evertjan.
                  The Netherlands.
                  (Please change the x'es to dots in my emailaddress)

                  Comment

                  • Dr John Stockton

                    #10
                    Re: Auto insert Date in form input field

                    JRS: In article <Xns9404EA3322F 18eejj99@194.10 9.133.29>, seen in
                    news:comp.lang. javascript, Evertjan. <exjxw.hannivoo rt@interxnl.net >
                    posted at Sun, 28 Sep 2003 21:01:17 :-[color=blue]
                    >Dr John Stockton wrote on 28 sep 2003 in comp.lang.javas cript:[color=green]
                    >> But everyone can understand 2004/04/11 as being the coming Easter
                    >> Sunday, given an adequate 2004 diary.[/color]
                    >
                    >In 2004 everywhere, but:
                    >
                    >"The Orthodox Easter usually falls later than the Catholic Easter,
                    >depending on when Passover is. The Russian Easter falls one week after
                    >Passover."
                    >
                    >Year 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010
                    >
                    >Catholic 23/4 15/4 31/3 20/4 11/4 27/3 16/4 8/4 23/3 12/4 4/4
                    >Orthodox 30/4 15/4 5/5 27/4 11/4 1/5 23/4 8/4 27/4 19/4 4/4[/color]

                    Not only "Catholic", but also "Protestant "; or, to give due credit,
                    "Gregorian" . The first row agrees with Zeller & other sources.

                    But, while I have reliable algorithms for Julian Easter, I have nothing
                    that gives the Orthodox row of dates. Is that Passover the Pesach of
                    the accepted Hebrew calendar, or is it some rival computation?

                    Hebrew Pesach is 15 Nisan, and the Hebrew Year rotates slowly against
                    the Gregorian; so, if it is the same Pesach, the attached Easter will
                    not remain with Gregorian April/May. OTOH, neither will remain forever
                    in accord with the actual seasons.
                    [color=blue]
                    >John, as a numbercruncher you will like this, I hope:
                    ><http://www.assa.org.au/edm.html>[/color]
                    Will look.

                    --
                    © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
                    Web <URL:http://www.merlyn.demo n.co.uk/> - w. FAQish topics, links, acronyms
                    PAS EXE etc : <URL:http://www.merlyn.demo n.co.uk/programs/> - see 00index.htm
                    Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.

                    Comment

                    Working...