Hello and welcome to our community! Is this your first visit?
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
    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.

    <!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">
    		<style type="text/css">
    			.myForm td, input {
    				font-family: tahoma;
    				font-size: 12px;
    			.required {
    				color: red;
    		<form method="post" action="%%FORMACTION%%">
    			<table border="0" class="myForm" cellpadding="2">
    	<td><span class="required">*</span>&nbsp;
    Your Email Address:</td>
    	<td><input type="text" name="email" value="%%Email%%" /></td>
    <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%% />
    						<input type="submit" value="Update your details" />
    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. #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Thanked 4,947 Times in 4,908 Posts
    <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;
    Be yourself. No one else is as qualified.


Posting Permissions

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