Click here to Skip to main content
15,888,232 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can anyone help me with this? I have a problem getting it to show the date in the input box. (this isn't my code).

HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
		<title>Untitled Document</title>
		<script type="text/javascript">
			var d=new Date();
			var monthname=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
			//Ensure correct for language. English is "January 1, 2004"
			var TODAY = monthname[d.getMonth()] + " " + d.getDate() + ", " + d.getFullYear();
			function today(){
				document.getElementById("txtBox").value = TODAY;
			}
		</script>
	</head>
	<body>
		<form>
			<input type="text" name="txtBox">
			<input type="button" value="Today" onclick="today()">
		</form>
	</body>
</html>


Thanks!

Joel.
Posted
Comments
Ron Beyer 23-Aug-13 11:23am    
So when you click the button, what happens? Nothing? Wrong format? Anything?

1 solution

Please try following code

XML
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>Untitled Document</title>
        <script type="text/javascript">
            var d = new Date();
            var monthname = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
            //Ensure correct for language. English is "January 1, 2004"
            var TODAY = monthname[d.getMonth()] + " " + d.getDate() + ", " + d.getFullYear();
            function today()
            {
                document.getElementById('txtBox').value = TODAY.toString();
                return false;
            }
        </script>
    </head>
    <body>
        <form>
            <input type="text" name="txtBox" id="txtBox">
            <input type="button" value="Today" onclick="return today()">
        </form>
    </body>
</html>
 
Share this answer
 
Comments
jba1991 23-Aug-13 12:35pm    
.toString() and return false are the parts that make the code work?

Thanks a lot :)
Sandeep Singh Shekhawat 23-Aug-13 12:40pm    
No @jba1991. The main part that I have added is id of input type field like <input type="text" name="txtBox" id="txtBox">
jba1991 23-Aug-13 14:51pm    
Oh i see. Thanks anyways :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900