Hello everyone,

I'm trying to combine 3 form input fields into 1 that is hidden (Date of Birth). The input fields are DOB-MM, DOB-DD, and DOB-YYYY and the hidden field is DOB which will store the Date of Birth in the following format 'YYYY-MM-DD'. Unfortunately I don't know javascript so I hope someone can help me write a quick script that will combine these 3 fields and arrange them in the format required.

Thank you in advance!

Cheers!

<form name="signup" action="{{{form_url}}}" class="appnitro" method="post" >
					<div class="form_description">
			<h2>Newsletter Sign-up</h2>
		</div>						
			<ul >
			
					<li id="li_1" >
		<label class="description" for="person_name">Name / Nombre </label>
		<span>
			<input id="person_first_name" name= "person[first_name]" class="element text" maxlength="255" size="20" value="{{{first_name}}}"/>
			<label>First Name / Nombre</label>
		</span>
		<span>
			<input id="person_last_name" name= "person[last_name]" class="element text" maxlength="255" size="20" value="{{{last_name}}}"/>
			<label>Last Name / Apellido</label>
		</span>		</li>		<li id="li_3" >
		<label class="description" for="person_email_address">Email / Correo Electronico * (Required)</label>
		<div>
			<input id="person_email_address" name="person[email_address]" class="element text medium" type="text" maxlength="255" value="{{{email_address}}}"/> 
		</div> 
		</li>		<li id="li_4" >
		<label class="description" for="person_dob">Date of Birth / Fecha de Nacimiento </label>
		<span>
			<input id="person_dobmm" name="person[dobmm]" class="element text" size="2" maxlength="2" value="{{{dobmm}}}" type="text"> /
			<label for="DOB-MM">MM</label>
		</span>
		<span>
			<input id="person_dobdd" name="person[dobdd]" class="element text" size="2" maxlength="2" value="{{{dobdd}}}" type="text"> /
			<label for="DOB-DD">DD</label>
		</span>
		<span>
	 		<input id="person_dobyyyy" name="person[dobyyyy]" class="element text" size="4" maxlength="4" value="{{{dobyyyy}}}" type="text">
			<label for="DOB-YYYY">YYYY</label>
		</span>
			<input id="person_dob" name="person[dob]" start_year="1910" type="hidden" value="{{{dob}}}" />
		</li>		
		
		<li class="buttons">
		    
				<input class="button_text" type="submit" name="commit" value="Sign Up" />
		</li>
			</ul>
		</form>
Member Avatar for rajarajan2017
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script language="javascript">
function check(){
	var text=yyyy.value+"-"+mm.value+'-'+dd.value;
	alert(dob.value);
	dob.value=text;
	alert(dob.value);
}
</script>
</head>
<body>
MM <input type="text" size="2" name="mm">
DD <input type="text" size="2" name="dd">
YY <input type="text" size="4" name="yyyy">
<input type="submit" name="commit" value="Submit" onClick="check()">
<input type="hidden" size="10" name="dob" value="test">
</body>
</html>

Hello RajaRajan.R,

Thank you for your reply. One quick question about your code. Should the value of the line below be test or text?

<input type="hidden" size="10" name="dob" value="test">

Regards,

TolucaDiablo

Member Avatar for rajarajan2017

Dont worry about that, it is "test" only it is a default value displayed in the hidden field, you can also leave it simply with "". We change the "test" to "1998-5-12" in javascript using that name of the hidden field.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.