filling today's date in a form

K

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.
 
F

Felipe Almeida Lessa

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.
 
K

Kun

Felipe said:
Em Dom, 2006-04-16 às 19:22 -0400, Kun escreveu:

Which kind of form? Which toolkit?


Enter the date in which kind of control?


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?
 
L

Lawrence D'Oliveiro

Kun <[email protected]> said:
... 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.
 
T

Tim Chase

Lawrence said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,293
Messages
2,571,500
Members
48,188
Latest member
GerardRush

Latest Threads

Top