Results 1 to 4 of 4

Thread: how to show current date in the input text field using variable

  1. #1
    Join Date
    Nov 2007
    Posts
    69
    Thanks
    36
    Thanked 0 Times in 0 Posts

    Default how to show current date in the input text field using variable

    hi
    i m unable to rectify this problem and m unable to get a solution also
    pls help me.
    i want to have the current date showing in the input field


    var cdat=(new Date());
    var newcdatsep1="-";
    var newcdat="00" + cdat.getDate();
    var newcdat1="00" + (cdat.getMonth()+1);
    newcdat=newcdat.substring(newcdat.length - 2);
    newcdat1=newcdat1.substring(newcdat1.length - 2);
    var newcdat3=newcdat+newcdatsep1+newcdat1;


    <td>Date</td>
    <td>
    <input type="text" value="newcdat3" tabindex="9" size="20">
    </td>

    here i thought the value should show me the current date but it is not showing anything
    what i have to do to achieve this
    if someone can help me rectify this i wud be really greatful
    thanks
    anand

  2. #2
    Join Date
    Nov 2007
    Posts
    69
    Thanks
    36
    Thanked 0 Times in 0 Posts

    Default

    can anyone help pls??????

  3. #3
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Well your date variables look sort of right, but you aren't actually applying it to the input field:

    Code:
    <input type="text" value="newcdat3" tabindex="9" size="20" id="date">
    <script type="text/javascript">
    $ = function(e) {return document.getElementById(e);};
    var x = new Date(),
      m = x.getMonth(),
      d = x.getDate(),
      y = x.getYear();
    $("date").value = (m<10?"0"+m:m)+"-"+(d<10?"0"+d:d)+"-"+y;
    </script>
    I couldn't figure out the date format you were trying to use, so I used the basic month-day-year format.
    - Mike

  4. The Following User Says Thank You to mburt For This Useful Post:

    meenakshi (05-16-2008)

  5. #4
    Join Date
    Nov 2007
    Posts
    69
    Thanks
    36
    Thanked 0 Times in 0 Posts

    Default

    hi
    wow it is actually working
    thanks a million
    smile always

    ur too good
    anand

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
  •