Solved

How to put today's date in a <input> tag

Posted on 1997-11-11
1
1,084 Views
Last Modified: 2013-12-25
I have a form and I need to include the
<input type="date" value="***">
*** as being today's date . It should automatically capture today's date and replace the *** .

Anyone know how to accomplish this?
Can this be done with javascript ? If so can anyone give me the code for it?

Thanks for any help !
0
Comment
Question by:anusha
1 Comment
 
LVL 6

Accepted Solution

by:
Holger101497 earned 100 total points
ID: 1855507
In Netscape Navigator, there is a very nice way of including JavaScript-values in HTML-code. The shortest form of that would look like this:
<input type=text name=dateinput value="&{new Date()};">
The string will always be in the format used on the local computer. If you don't like that format, you will have to assign the value "the hard way" ;-)

  <form name=form1>
    <input name=dateinput type=text value="&{(new Date())};">
  </form>
  <script>
     D = new Date();
     document.form1.dateinput.value=D.getMonth()+"-"+D.getDate()+"-"+D.getYear();
  </script>

If you have more values to initialize, it might be better to place all these initializations into a separate function and call it in the "onload" handler of the body:
<BODY .... onload="Initialize()">

Good luck! Let me nkow if you have any questions...

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now