Lawrence D'Oliveiro wrote: > In article <[EMAIL PROTECTED]>, Kun <[EMAIL PROTECTED]> > 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 -- http://mail.python.org/mailman/listinfo/python-list