By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,462 Members | 3,388 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,462 IT Pros & Developers. It's quick & easy.

Adding Date/Time to an HTML form? - Request_Information_b.html (0/1)

P: n/a
I'm trying to add a date and time to an html form, but I'm having a
bit of trouble getting it working. Any suggestions?

Thanks!
~ David (merlin001_at_gmail_dot_com)
Jun 20 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Lee
David <merlin001 said:
>
I'm trying to add a date and time to an html form, but I'm having a
bit of trouble getting it working. Any suggestions?
This is a text newsgroup.
Please don't post encoded attachments.
If you want to post html, just copy and paste it into your message.
If it's too long, or you don't want to strip out enough whitespace
to make it readable when posted, put it on the web and post an URL.

<html>
<body>
<p>This won't hurt any decent newsreader</p>
</body>
</html>
--

Jun 20 '07 #2

P: n/a
me
Sorry, I'm still learning newsgroups. Okay, the text follows. I'm just trying
to get a date/time as a field in the submitted form.

<html><head><title>Request Information</title>

<script type="text/javascript">

var currentHour = "";

var currentMinute = "";

var currentSeconds = "";

var DateAndTime = "";

var AMPM = "";

var currentTime = "";

var currentDate = "";

var currentMonth = "";

var newMonth = "";

var currentDay = "";

var currentYear = "";

function getCurrentTime() {

DateAndTime = new Date();

currentDate = getCurrentDate();

currentHour = DateAndTime.getHours();

if (currentHour >= 12)

{ AMPM = "PM"; currentHour = currentHour - 12; }

else if (currentHour == 0)

{ AMPM = "AM"; currentHour = 12; }

else

{ AMPM = "AM"; }

currentMinute = DateAndTime.getMinutes();

currentSeconds = DateAndTime.getSeconds();

if (currentSeconds < 10)

{ currentSeconds = "0" + currentSeconds; }

currentTime = currentHour + ":" + currentMinute + ":" + currentSeconds +
" " + AMPM;

return dateAndTime; }

function getCurrentDate() {

currentMonth = DateAndTime.getMonth();

currentDay = DateAndTime.getDay();

currentYear = DateAndTime.getFullYear();

switch (currentMonth) {

case 0: { newMonth = "January"; break; }

case 1: { newMonth = "February"; break; }

case 2: { newMonth = "March"; break; }

case 3: { newMonth = "April"; break; }

case 4: { newMonth = "May"; break; }

case 5: { newMonth = "June"; break; }

case 6: { newMonth = "July"; break; }

case 7: { newMonth = "August"; break; }

case 8: { newMonth = "September"; break; }

case 9: { newMonth = "October"; break; }

case 10: { newMonth = "November"; break; }

case 11: { newMonth = "December"; break; } }

thisDate = newMonth + " " + currentDay + ", " + currentYear;

return thisDate; }

</script>

</head>

<body bgcolor="black" text="white">

<h1 align="center">Request Information</h1>

<form method="post" action="mailto:pe****@domain.com">

<h3>Contact Information:</h3>

First name:<input type="text" name="firstname"><br />

Last name:<input type="text" name="lastname"><br />

Company:<input type="text" name="company"><br />

Address 1:<input type="text" name="address1"><br />

Address 2:<input type="text" name="address2"><br />

City:<input type="text" name="city">

Zip Code:<input type="text" name="zipcode"><br />

Phone Number:<input type="text" name="phone"><br />

E-Mail Address:<input type="text" name="email"><br /><br />

<input type="hidden" name="dateTime" value="getCurrentTime()">

<input type="submit" value="Submit" />

<input type="reset" value="Reset" />

</form>

</body>

</html>
--
--------------------------------- --- -- -
Posted with NewsLeecher v3.9 Beta 1
Web @ http://www.newsleecher.com/?usenet
------------------- ----- ---- -- -

Jun 20 '07 #3

P: n/a
On Jun 20, 3:05 pm, me (m...@somewhere.com) wrote:
Sorry, I'm still learning newsgroups. Okay, the text follows. I'm just trying
to get a date/time as a field in the submitted form.
[...]
<input type="hidden" name="dateTime" value="getCurrentTime()">
You can insert script[1] as the value of attributes that represent
intrinsic event handlers such as onclick, onfocus, onblur, etc. The
HTML specification lists those that are appropriate for each
element[2]. Putting script into some other attribute makes its value
the literal characters, the script isn't executed.

Presumably you'd like to get the time that the user submitted the
form. Why not just get that when the server gets the post request? No
need for script, hoping that the user has their system clock set
correctly or dealing with time zones.

1. Basic HTML Data Types - Script
<URL: http://www.w3.org/TR/html4/types.html#type-script >

2. W3C HTML 4 specification
<URL: http://www.w3.org/TR/html4/ >
--
Rob

Jun 20 '07 #4

P: n/a
In comp.lang.javascript message <v78h735l6bi5am6cr7sfssp749vljhk20t@4ax.
com>, Tue, 19 Jun 2007 20:37:59, David <merlin001@?.?.com.invalid>
posted:
>I'm trying to add a date and time to an html form, but I'm having a
bit of trouble getting it working. Any suggestions?
You should read the newsgroup FAQ with care - especially with an e-
address like "yours".

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Jun 20 '07 #5

P: n/a
In comp.lang.javascript message <46***********************@unlimited.new
shosting.com>, Wed, 20 Jun 2007 05:05:14, me@?.?.invalid posted:
>Sorry, I'm still learning newsgroups. Okay, the text follows. I'm just trying
to get a date/time as a field in the submitted form.
Only really silly people use the 12-hour clock in internal data
processing. The generic adjective for them is "Americans". Granted,
/hoi polloi/ use it in other countries too; but at least they generally
understand the 24-h clock.

Your organisation should either engage a trained Javascript programmer,
or buy you a copy of "Javascript for Dummies". You clearly have a
grossly inadequate understanding of Javascript programming.

The following, with "text" restored to "hidden", will do substantially
what you need, loading the field with a recognisable date[*].

<input type="text" ID="dateTime" size=33>
<script>
document.getElementById("dateTime").value = new Date()
</script>

But, as the date will presumably be read by a machine, you can use +
before new Date() to get a more machine-friendly form.

Remember, if your clientele span more than one offset from GMT, to think
carefully about whether client's date, server date, or standard date
should be used. Often, absolute time is better.

Read the current Risks Digest 24.70 9/10 (news:comp.risks) and see the
folly of using date-and-time at all when a simple absolute scale of
seconds (converted for display if needed) is appropriate. It seem that
Raptors turn by 180 degrees - I don't know about what axis - on crossing
the Date Line.
[*] But of browser-dependent form.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6.
Web <URL:http://www.merlyn.demon.co.uk/- w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/- see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Jun 20 '07 #6

P: n/a
Dr J R Stockton said the following on 6/20/2007 4:34 PM:
In comp.lang.javascript message <46***********************@unlimited.new
shosting.com>, Wed, 20 Jun 2007 05:05:14, me@?.?.invalid posted:
>Sorry, I'm still learning newsgroups. Okay, the text follows. I'm just trying
to get a date/time as a field in the submitted form.

Only really silly people use the 12-hour clock in internal data
processing. The generic adjective for them is "Americans".
I see your ugly bias has surfaced again. It displays your ignorance, not
your intelligence John.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 21 '07 #7

P: n/a
In comp.lang.javascript message <ob********************@telcove.net>,
Thu, 21 Jun 2007 00:31:36, Randy Webb <Hi************@aol.composted:
>
I see your ugly bias has surfaced again. It displays your ignorance,
not your intelligence John.
Stop whining and get on with the work which you promised to do, the
maintenance of the newsgroup FAQ. It's now over ninety days since the
date of FAQ - 9.70 - 2007-03-22, and since then many suggestions have
been made in response to the daily postings-for-comment.

--
(c) John Stockton, Surrey, UK. ??*@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/- FAQish topics, acronyms, & links.
Check boilerplate spelling -- error is a public sign of incompetence.
Never fully trust an article from a poster who gives no full real name.
Jun 21 '07 #8

P: n/a
Dr J R Stockton said the following on 6/21/2007 3:38 PM:
In comp.lang.javascript message <ob********************@telcove.net>,
Thu, 21 Jun 2007 00:31:36, Randy Webb <Hi************@aol.composted:
>I see your ugly bias has surfaced again. It displays your ignorance,
not your intelligence John.

Stop whining
The only one whining is you. If the truth hurts, bear the pain and move
on as it changes nothing about your ignorant bias.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 22 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.