Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Automatic / when date is entered

    Does anybody know how to automate the / to separate the month, date and year in a textbox?
    Example as i type the month 06, it will insert / afterwards. then i type the day 12 and inserts another / then i type the year

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    For dates, you would be much better off using 3 different text boxes or 3 different dropdown boxes and concatenating them when you're all done.

    This code works, assuming the user enters the month and date as 2 character strings (i.e. 01/01/2001 instead of 1/1/2001). You can modify it to allow for 1 character dates, but I think three different boxes is the best solution.

    <html>
    <head>
    <script language="javascript">
    function checkLength(my_textbox){
    if ((my_textbox.value.length==2) || (my_textbox.value.length==5))
    my_textbox.value+="/";
    }
    </script>
    </head>
    <body>
    <form>
    <input type="text" name="datebox" onkeyup="checkLength(this);">
    <input type="submit">
    </form>
    </body>
    </html>

  • #4
    Regular Coder
    Join Date
    Dec 2002
    Posts
    169
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Automatic / when date is entered

    Originally posted by carrera
    Does anybody know how to automate the / to separate the month, date and year in a textbox?
    Example as i type the month 06, it will insert / afterwards. then i type the day 12 and inserts another / then i type the year
    If you want a convenient way for the user to enter a valid date into a textfield, you might be interested in this example. Like a file upload component (a textfield for the local file path, plus a "Browse..." button), this date entry implementation offers a readonly textfield to receive the chosen date (MM/DD/YYYY), and a "Calendar..." button to popup a fully-navigable cross-browser calendar.

    Let me know if this is something you can use. I may even be able to help you adapt it to suit your particular application.

    :ca_redwards.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •