[thelist] Use client-side date and time in asp.net
Ken Schaefer
ken at adOpenStatic.com
Mon May 10 00:13:55 CDT 2004
If you do not use a server control, then you can manually get the value of
the field out of the Request.Form() collection.
If you use a server control, then your javascript needs to know the name of
that control, so as to set it's value.
Cheers
Ken
----- Original Message -----
From: "Jeff Ervin" <jberv534 at verizon.net>
To: "The List" <thelist at lists.evolt.org>
Sent: Monday, May 10, 2004 2:28 PM
Subject: RE: [thelist] Use client-side date and time in asp.net
: I have not been able to get the date created via html page into the code
: behind. An compile error is created when I use a hidden field because it
has
: not been declared. If I use a declared field, the date is not being put in
: the field in that case.
:
: I followed the example, but must be missing something else.
:
: -----Original Message-----
: From: David T-G [mailto:davidtg-thelist at justpickone.org]
: Sent: Sunday, May 09, 2004 9:06 PM
: To: The List
: Cc: Jeff Ervin
: Subject: Re: [thelist] Use client-side date and time in asp.net
:
:
: Jeff, et al --
:
: ...and then Jeff Ervin said...
: %
: % I have seen references to using the client's date and time in an asp.net
: % page, but nothing complete.
:
: Note that that really has nothing to do with ASP; the magic is in the
: javascript that is sent down to the client.
:
:
: %
: % Below is the code taken from an earlier archive:
: % <script>
: % function SetDateTime() {
: % document.frmAddEditNewRequests.HiddenDateTime.value = new Date();
: % // Change myForm to the name of your Form
: % }
: % </script>
:
: This part is the javascript. It says that when this function, called
: SetDateTime, is run, it will set the value of the field HiddenDateTime in
: the frmAddEditNewRequests object (probably a form) to the current date --
: as seen by the browser, that is.
:
:
: %
: % In the form tag add:
: %
: % onSubmit="SetDateTime()"
:
: In order to make that function do something, you have to actually call
: it. This says that when the submit button is pushed the browser should
: also execute that javascript function.
:
:
: %
: %
: % In your form add:
: %
: % <input type="hidden" name="HiddenDateTime" value=""
:
: This just defines the field in your form. You could call it MyDate or
: TheLocalTime or gOOfbAll if you wanted -- as long as you also changed the
: name up above in the javascript.
:
:
: %
: % I don't understand how to reference HiddenDateTime.
: %
: % please help, if possible.
:
: I speak PHP, so I'll give a PHP example. Your page would look something
: like
:
: <!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.0 Transitional//EN'
: 'http://www.w3.org/TR/html4/loose.dtd'>
: <html>
: <head>
: <meta http-equiv='content-type' content='text/html;
: charset=iso-8859-1'>
: <title>What time is it?</title>
: <script language='javascript'>
: function setdatetime()
: { document.timeform.pctime.value = new Date(); }
: </script>
: </head>
: <body>
: <?php
: if ( isset($_POST['pctime']) )
: {
: print "The time on your PC is " ;
: print ">>{$_POST['pctime']} <<.<br>\n" ;
: }
: else
: {
: print "What time is it?<br>\n" ;
: print "<form method='post' name='timeform'
: onsubmit='setdatetime()'>\n" ;
: print "Input anything here; it does not matter.<br>\n" ;
: print "<input type='text' name='textinput' size='20'><br>\n" ;
: print "Say anything you want in the form.<br>\n" ;
: print "<input type='hidden' name='pctime' value=''>\n" ;
: print "Finally, ...\n" ;
: print "<input type='submit' value='Click to find out!'><br>\n" ;
: print "</form>\n" ;
: }
: ?>
: </body>
: </html>
:
: which you can see in action at
:
: http://justpickone.org/davidtg/private/whattime.php
:
: and read in source at
:
: http://justpickone.org/davidtg/private/whattime.phps
:
: as well. Note that I called my field pctime instead of HiddenDateTime;
: it's just a name.
:
:
: %
: % Thanks
:
:
: HTH & HAND
:
: :-D
: --
: David T-G
: davidtg at justpickone.org
: http://justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg!
:
:
:
: --
: * * Please support the community that supports you. * *
: http://evolt.org/help_support_evolt/
:
: For unsubscribe and other options, including the Tip Harvester
: and archives of thelist go to: http://lists.evolt.org
: Workers of the Web, evolt !
:
More information about the thelist
mailing list