Solved

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

Posted on 1997-11-11
1
1,096 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

726 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