SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot Run2Web's Avatar
    Join Date
    Apr 2002
    Location
    Indiana
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Self-Correcting Date?

    Hi,

    I have a text box that allows the user to enter the date. They want to be able to enter the date with no separators (like 03052002) and on tab have the date automatically self correct to show the correct date format of 2002-03-05 (YYYY-MM-DD). Is there a way to do this that won't conflict with my php that is used in the page? The name of the text box can't change do to backend processing.

    TIA

    Run2Web
    RUN2Web

    Has Anyone seen my Furry Little Mind?

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    function formatDate(elem) {
    var temp = elem.value.replace(/\D/g,"");
    elem.value = temp.replace(/(\d{4})(\d{2})(\d{2})/,"$1-$2-$3");
    }

    <input type="text" name="date" onBlur="formatDate(this)" />
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  3. #3
    SitePoint Zealot Run2Web's Avatar
    Join Date
    Apr 2002
    Location
    Indiana
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks beetle, that looks like it may work.

    Now for a really dumb question?

    Where would I place this function? I know that with JavaScript some things have to go in the head and other things elsewhere.
    RUN2Web

    Has Anyone seen my Furry Little Mind?

  4. #4
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If javascript is nicely placed in a function, it doesn't matter where it goes. However, to satisfy logic, convention, readability, and debugging, it's best to put your scripting in the <HEAD>
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  5. #5
    SitePoint Zealot Run2Web's Avatar
    Join Date
    Apr 2002
    Location
    Indiana
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This works beautifully!

    Thanks!
    RUN2Web

    Has Anyone seen my Furry Little Mind?


Bookmarks

Posting Permissions

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