SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot ant1832's Avatar
    Join Date
    Apr 2002
    Location
    Tucson, AZ
    Posts
    176
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using document.write to write current date to input value.

    Why doesn't this work?
    The input field doesn't show up at all. I know I'm just missing something really simple here. Please help me out.
    Code:
    <script type="text/javascript">
    day = day.getDay()+1; 
    month = day.getMonth()+1;
    year = day.getYear(); 
    newdate= month + '/' + day + '/' + year;
    document.write('<INPUT name=Date value='+ newdate + '>');
    </script>

  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)
    You need a Date() object! (oh, and better declare those variables....)
    Code:
    <script type="text/javascript">
    var d = new Date();
    var day = d.getDay()+1;
    var month = d.getMonth()+1;
    var year = d.getYear();
    var newdate= month + '/' + day + '/' + year;
    document.write('<INPUT name="Date" value="'+ newdate + '">');
    </script>
    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 ant1832's Avatar
    Join Date
    Apr 2002
    Location
    Tucson, AZ
    Posts
    176
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Whoops...obviously i copied that code from an old post(see i search). I didn't realize that was importanta.

    Thanks again beetle.


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
  •