Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hidden date field

Status
Not open for further replies.

sborny

Technical User
Jun 29, 2001
157
GB
Hi,

I need to know how to add a hidden field that is todays date to a html form so that when you submit the date field is sent with the rest of it.

Thanks

Symon

Everything has an answer, it's just knowing the right question to ask. !!!!
 
In JavaScript, create a variable set equal to 'new Date()'. That is now. You might have to play around with the parsing to get it into the format you want, but you can use myDate.getMonth() ...getYear(), etc. and concatenate together the date you want.

Anyway, I THINK that's the most readily-available option to you.

'hope this helps.

--Dave
 
Thanks dave,

Once that is done, how do you put that value into a field on the html form.

cheers

Symon.

Everything has an answer, it's just knowing the right question to ask. !!!!
 
Still in the JavaScript:

formName.fieldName.value = myConcatenatedDateString;

In this case 'value' needs to be 'value', but the other stuff would be YOUR form name, hidden field name, and JavaScript variable name, respectively.

Let me know if you can't get it working.

Good luck!

--Dave
 
Building on what Dave said, try something like this:
Code:
<html>
<head>
<title>Untitled</title>

<script language="JavaScript" type="text/javascript">
<!--
function addDate(){
	document.dateForm.date.value = Date();
	return true;
}
//-->
</script>

</head>
<body>
<form action="page2.html" method="post" name="dateForm" onsubmit="return addDate();">
	<input type="hidden" name="date" value="" />
	<input type="submit" value="Submit" />
</form>
</body>
</html>
NOTE: The Date() function in Javascript IS case-sensitive. For more info on using date and time in javascript, go here:
Hope that helps,
Ron

“If you are irritated by every rub, how will you be polished?”
~ Mevlana Rumi


murof siht edisni kcuts m'I - PLEH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top