simple date entry??

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

    #1

    simple date entry??

    I know this should be simple...but for some reason my brain isn't working.

    I want my users to enter a the date in three seperate boxes. After the
    users enters in two digits for the month I want the cursor to move to the
    day textbox and so on....

    I was using simple code...but onKeyPress occurs before the value
    changes...can anyone help me?

    my code:
    <form name="frmdatebo xes" action="test2.a sp" method="post">
    <input type="hidden" name="hidBBdate " value="">
    <input type="text" name="txtmonth" class="smalltxt box" maxlength="2"
    onKeyPress="che cklen(this,2);" > /
    <input type="text" name="txtday" class="smalltxt box" maxlength="2"
    onKeyPress="che cklen(this,2);" > /
    <input type="text" name="txtyear" class="txtbox" maxlength="4"
    onKeyPress="che cklen(this,4);" >
    </form>

    function checklen(tFormO bj, tLen)
    {
    if (tFormObj.value .length == tLen)
    {
    document.forms["frmdatebox es"].nextelement.fo cus();
    }
    }


    TIA
    -Bruce Duncan


  • Bruce Duncan

    #2
    Re: simple date entry??


    "Bruce Duncan" <bruce~w~duncan @~hotmail.com> wrote in message
    news:10ahtkalca h4h5a@corp.supe rnews.com...[color=blue]
    > I know this should be simple...but for some reason my brain isn't working.
    >
    > I want my users to enter a the date in three seperate boxes. After the
    > users enters in two digits for the month I want the cursor to move to the
    > day textbox and so on....
    >
    > I was using simple code...but onKeyPress occurs before the value
    > changes...can anyone help me?
    >
    > my code:
    > <form name="frmdatebo xes" action="test2.a sp" method="post">
    > <input type="hidden" name="hidBBdate " value="">
    > <input type="text" name="txtmonth" class="smalltxt box" maxlength="2"
    > onKeyPress="che cklen(this,2);" > /
    > <input type="text" name="txtday" class="smalltxt box" maxlength="2"
    > onKeyPress="che cklen(this,2);" > /
    > <input type="text" name="txtyear" class="txtbox" maxlength="4"
    > onKeyPress="che cklen(this,4);" >
    > </form>
    >
    > function checklen(tFormO bj, tLen)
    > {
    > if (tFormObj.value .length == tLen)
    > {
    > document.forms["frmdatebox es"].nextelement.fo cus();
    > }
    > }
    >
    >
    > TIA
    > -Bruce Duncan
    >[/color]

    It seems to work if I change the function call from onKeyPress to onKeyUp.
    Does anyone know of a better way?

    -bruce duncan


    Comment

    • kaeli

      #3
      Re: simple date entry??

      In article <10ahtkalcah4h5 a@corp.supernew s.com>,
      bruce~w~duncan@ ~hotmail.com enlightened us with...[color=blue]
      > I know this should be simple...but for some reason my brain isn't working.
      >
      > I want my users to enter a the date in three seperate boxes. After the
      > users enters in two digits for the month I want the cursor to move to the
      > day textbox and so on....
      >
      > I was using simple code...but onKeyPress occurs before the value
      > changes...can anyone help me?
      >[/color]

      Use onKeyUp, but form.nextelemen t is not valid in Netscape. Actually, it
      didn't work in IE, either. I don't know what you were going for with
      that.
      However, the event did fire at the proper time, after the value was
      changed.

      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
      "http://www.w3.org/TR/REC-html40/loose.dtd">
      <html>
      <head>
      <title> New Document </title>
      <script type="text/javascript">
      function checklen(tFormO bj, tLen)
      {
      alert(tFormObj. value);
      if (tFormObj.value .length == tLen)
      {
      document.forms["frmdatebox es"].nextelement.fo cus();
      }
      }
      </script>
      </head>

      <body>
      <form name="frmdatebo xes" action="test2.a sp" method="post">
      <input type="hidden" name="hidBBdate " value="">
      <input type="text" name="txtmonth" class="smalltxt box" maxlength="2"
      onKeyUp="checkl en(this,2);"> /
      <input type="text" name="txtday" class="smalltxt box" maxlength="2"
      onKeyUp="checkl en(this,2);"> /
      <input type="text" name="txtyear" class="txtbox" maxlength="4"
      onKeyUp="checkl en(this,4);">
      </form>


      </body>
      </html>


      --
      --
      ~kaeli~
      He's your God, they're your rules - you burn in Hell.



      Comment

      • Bruce Duncan

        #4
        Re: simple date entry??

        "Bruce Duncan" <bruce~w~duncan @~hotmail.com> wrote in message
        news:10ahtkalca h4h5a@corp.supe rnews.com...[color=blue]
        > I know this should be simple...but for some reason my brain isn't working.
        >
        > I want my users to enter a the date in three seperate boxes. After the
        > users enters in two digits for the month I want the cursor to move to the
        > day textbox and so on....
        >
        > I was using simple code...but onKeyPress occurs before the value
        > changes...can anyone help me?
        >
        > my code:
        > <form name="frmdatebo xes" action="test2.a sp" method="post">
        > <input type="hidden" name="hidBBdate " value="">
        > <input type="text" name="txtmonth" class="smalltxt box" maxlength="2"
        > onKeyPress="che cklen(this,2);" > /
        > <input type="text" name="txtday" class="smalltxt box" maxlength="2"
        > onKeyPress="che cklen(this,2);" > /
        > <input type="text" name="txtyear" class="txtbox" maxlength="4"
        > onKeyPress="che cklen(this,4);" >
        > </form>
        >
        > function checklen(tFormO bj, tLen)
        > {
        > if (tFormObj.value .length == tLen)
        > {
        > document.forms["frmdatebox es"].nextelement.fo cus();
        > }
        > }
        >
        >
        > TIA
        > -Bruce Duncan
        >[/color]
        I should post the code that works...sorry:

        function checklen(tFormO bj, tLen, tNextObj)
        {
        if (tFormObj.value .length == tLen)
        {
        document.forms["frmdatebox es"][tNextObj].focus();
        }
        }

        <form name="frmdatebo xes" action="test2.a sp" method="post">
        <input type="hidden" name="hidBBdate " value="">
        <input type="text" name="txtmonth" class="smalltxt box" maxlength="2"
        onKeyUp="checkl en(this,2,'txtd ay');"> /
        <input type="text" name="txtday" class="smalltxt box" maxlength="2"
        onKeyUp="checkl en(this,2,'txty ear');"> /
        <input type="text" name="txtyear" class="txtbox" maxlength="4">
        </form>

        -Bruce Duncan


        Comment

        • Mick White

          #5
          Re: simple date entry??

          Bruce Duncan wrote:

          [color=blue]
          >
          > It seems to work if I change the function call from onKeyPress to onKeyUp.
          > Does anyone know of a better way?
          >
          > -bruce duncan
          >[/color]
          If the number is a two digit number, this will not work. In fact I don't
          know if there is a way to do what you want, since you don't know when
          the user is finished with the entry.
          Mick

          Comment

          • Lee

            #6
            Don't do that [Re: simple date entry??]

            Bruce Duncan said:
            [color=blue]
            >I want my users to enter a the date in three seperate boxes. After the
            >users enters in two digits for the month I want the cursor to move to the
            >day textbox and so on....[/color]

            That's a very annoying thing for a user interface to do.

            Almost every text entry field requires you to hit TAB
            afterward. If you change the rules in a few cases
            you're not making things any easier.

            If you're doing this to prevent mistakes, you're not
            helping either. Most of the time that I make a typing
            error, I realize it immediately and hit backspace and
            then the correct character. If the focus moved to a
            new field after I typed the error, by backspace didn't
            correct it, and now I have errors in two fields.

            I don't like having to slow down and look to see if some
            clever programmer is going to make the focus move away
            from where I expect it to be.

            Comment

            • Bruce Duncan

              #7
              Re: Don't do that [Re: simple date entry??]

              "Lee" <REM0VElbspamtr ap@cox.net> wrote in message
              news:c8bl9b025n b@drn.newsguy.c om...[color=blue]
              > Bruce Duncan said:
              >[color=green]
              > >I want my users to enter a the date in three seperate boxes. After the
              > >users enters in two digits for the month I want the cursor to move to the
              > >day textbox and so on....[/color]
              >
              > That's a very annoying thing for a user interface to do.
              >
              > Almost every text entry field requires you to hit TAB
              > afterward. If you change the rules in a few cases
              > you're not making things any easier.
              >
              > If you're doing this to prevent mistakes, you're not
              > helping either. Most of the time that I make a typing
              > error, I realize it immediately and hit backspace and
              > then the correct character. If the focus moved to a
              > new field after I typed the error, by backspace didn't
              > correct it, and now I have errors in two fields.
              >
              > I don't like having to slow down and look to see if some
              > clever programmer is going to make the focus move away
              > from where I expect it to be.[/color]

              Good Point Lee...

              The more I think about it...the more I agree. Unless the user specifically
              asks, I won't use this method.

              ....but at least I can if I need to..

              -Bruce Duncan


              Comment

              • Dr John Stockton

                #8
                Re: simple date entry??

                JRS: In article <10ahtkalcah4h5 a@corp.supernew s.com>, seen in
                news:comp.lang. javascript, Bruce Duncan <bruce~w~duncan @~hotmail.com>
                posted at Mon, 17 May 2004 13:29:44 :[color=blue]
                >I know this should be simple...but for some reason my brain isn't working.
                >
                >I want my users to enter a the date in three seperate boxes. After the
                >users enters in two digits for the month I want the cursor to move to the
                >day textbox and so on....[/color]

                Tiresome for the user.

                Better to have a single box, in which YYYYMMDD can be entered
                with/without field separators. Consider a validation function built on
                :-

                S = "12340608"

                X = S.match(/^(\d\d\d\d)(\D? )(\d\d)(\2)(\d\ d)$/)
                if (!X) { alert("!") ; /* return false */ }
                Y = +X[1] ; M = +X[3] ; D = +X[5]
                with (Z = new Date(Y, M-1, D))
                OK = getMonth()+1 == M && getDate() == D
                // return OK

                --
                © 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> jscr maths, dates, sources.
                <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

                Comment

                Working...