Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Add current date to web form using Javascript

    I have the following form that needs to have the date inserted using Javascript.

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    	<head>
    <title></title>
    		<style type="text/css">
    
    			.myForm td, input {
    				font-family: tahoma;
    				font-size: 12px;
    			}
    
    			.required {
    				color: red;
    			}
    
    		</style>
    	</head>
    	<body>
    		<form method="post" action="%%FORMACTION%%">
    			<table border="0" class="myForm" cellpadding="2">
    				<tr>
    	<td><span class="required">*</span>&nbsp;
    Your Email Address:</td>
    	<td><input type="text" name="email" value="%%Email%%" /></td>
    </tr>
    <input type="hidden" id="CustomFields_30_dd" name="CustomFields[30][dd]" value="26"%%CustomField_30_01_dd%% />
    <input type="hidden" id="CustomFields_30_mm" name="CustomFields[30][mm]" value="08"%%CustomField_30_01_mm%% />
    <input type="hidden" id="CustomFields_30_yy" name="CustomFields[30][yy]" value="2013"%%CustomField_30_2008_yy%% />
    <input type="hidden" id="lists_3" name="lists[]" value="3"%%Lists_3%% />
    <input type="hidden" id="lists_8" name="lists[]" value="8"%%Lists_8%% />
    
    				<tr>
    					<td>&nbsp;</td>
    					<td>
    						<input type="submit" value="Update your details" />
    						</td>
    				</tr>
    			</table>
    		</form>
    	</body>
    </html>
    value="26" needs to be replaced with the current day.
    value="08" needs to be replaced with the current month.
    value="2013" needs to be replaced with the current year.

    Thanks in advance for your help.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,028
    Thanks
    75
    Thanked 4,325 Times in 4,291 Posts
    Code:
    <input type="hidden" id="CustomFields_30_dd" name="CustomFields[30][dd]" value="26"/>
    <input type="hidden" id="CustomFields_30_mm" name="CustomFields[30][mm]" value="08"/>
    <input type="hidden" id="CustomFields_30_yy" name="CustomFields[30][yy]" value="2013"/>
    ...
    
    <!-- put this script at the BOTTOM OF THE PAGE, just before the </body> tag ->
    <script type="text/javascript">
    var now = new Date();
    document.getElementById("CustomFields_30_yy").value = now.getFullYear();
    var mm = now.getMonth() + 1;
    if ( mm < 10 ) mm = "0" + mm;
    document.getElementById("CustomFields_30_mm").value = mm;
    var dd = now.getDate();
    if (dd < 10 ) dd = "0" + dd;
    document.getElementById("CustomFields_30_dd").value = dd;
    </script>
    </body>
    </html>
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •