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

filling today's date in a form

P: n/a
Kun
i have a form which takes in inputs for a mysql query. one of the inputs
is 'date'. normally, a user has to manually enter a date, but i am
wondering if there is a way to create a button which would automatically
insert today's date in the date form field if the user chooses to use
today's date.
Apr 16 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Em Dom, 2006-04-16 *s 19:22 -0400, Kun escreveu:
i have a form
Which kind of form? Which toolkit?
which takes in inputs for a mysql query. one of the inputs
is 'date'. normally, a user has to manually enter a date,
Enter the date in which kind of control?
but i am
wondering if there is a way to create a button which would automatically
insert today's date in the date form field if the user chooses to use
today's date.


Almost 100% sure that there is, but I can't tell you if or how if you
don't tell us how you are doing what you are doing.

--
Felipe.

Apr 16 '06 #2

P: n/a
Kun
Felipe Almeida Lessa wrote:
Em Dom, 2006-04-16 *s 19:22 -0400, Kun escreveu:
i have a form


Which kind of form? Which toolkit?
which takes in inputs for a mysql query. one of the inputs
is 'date'. normally, a user has to manually enter a date,


Enter the date in which kind of control?
but i am
wondering if there is a way to create a button which would automatically
insert today's date in the date form field if the user chooses to use
today's date.


Almost 100% sure that there is, but I can't tell you if or how if you
don't tell us how you are doing what you are doing.

Form is an html form called by a python cgi file using fieldstorage.

Date as in '2006-04-16'... is that what you meant by control?
Apr 17 '06 #3

P: n/a
In article <e1***********@netnews.upenn.edu>, Kun <ne*******@gmail.com>
wrote:
... but i am
wondering if there is a way to create a button which would automatically
insert today's date in the date form field if the user chooses to use
today's date.


If you're going to have a button to do it, then the button might as well
invoke a JavaScript sequence to fill in the field. No sense bothering
the server with something this simple.
Apr 17 '06 #4

P: n/a
Lawrence D'Oliveiro wrote:
In article <e1***********@netnews.upenn.edu>, Kun <ne*******@gmail.com>
wrote:

... but i am
wondering if there is a way to create a button which would automatically
insert today's date in the date form field if the user chooses to use
today's date.

If you're going to have a button to do it, then the button might as well
invoke a JavaScript sequence to fill in the field. No sense bothering
the server with something this simple.


If JavaScript is enabled, the following example will do what
the OP wants:

<html>
<head>
<script type="text/javascript">
function getDate()
{
alert("getting date...");
var d = new Date();
var s = d.toLocaleString();
alert(s);
return s;
}
function setDate()
{
alert("Setting date");
document.getElementById("myDate").value = getDate();
}
</script>
</head>

<body>
<form name="form1">
Date: <input type="text" id="myDate" size="20" />
<br /><br />
<input type="button" value="Today's Date" onclick="setDate();">
</form>
</body>

</html>

However, if JS is not enabled (as I often surf, given how
requisite JS is for many attack vectors and popups...thank
goodness for the NoScript plugin for FireFox which allows me
to whitelist sites allowed to use JS), your only hope is to
round-trip the server where your CGI/mod_python/whatever
script is sitting generating the page. Or populate the
field by default (using 'value="1/2/03"' attribute on your
textbox) when creating the field and let the user change it
if needed. The ideal is to prepopulate the field to the
most frequently used value so that the user has as little
work to do as possible.

You'll find some great tools on JavaScript over at the
http://www.w3schools.com site where you can experiment with
their TryIt editor. That will at least allow you to tinker
with the JS. You haven't provided enough details regarding
your web-scripting environment (Django, CGI, TG, mod_python...)

-tkc

Apr 17 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.