textbox date

H

hrider1

I have a form that updates a database and I would like to show the current
system date in a textbox on the form when the form is opened. Can someone
pllease tell me how this can be done or were I can find the information on
how to do this.
 
K

Kevin Spencer

You'll save yourself a lot of trouble if you can settle for the Date on the
client machine. Just use JavaScript:


<form...>

<input type="text" name="T1" id="TextBoxId" size="20" value="">

</form>
<script type="text/javascript"><--
document.getElementById("TextBoxId").Value = Date();
--></script>

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.
 
H

hrider1

After putting this into my page, the textbox still has no system date in it.
Could you tell me what I my be over looking?
Jim
 
R

Ronx

Try
<form...>

<input type="text" name="T1" id="TextBoxId" size="20" value="">

</form>
<script type="text/javascript"><!--
document.forms[0].T1.value = Date();
--></script>

This assumes the text box is in the first form that appears in the page
HTML.
 
P

p c

Ronx's suggestion works. The date is presented in Javasdcript's weird
date/time format. To present it in a standard format such as mm/dd/yyyy,
revise it to this:

<input type="text" name="T1" id="TextBoxId" size="20" value="">

</form>
<script type="text/javascript">
<!--
var today = new Date();
var month = today.getMonth() + 1;
var day = today.getDate();
var year = today.getFullYear();
var s = "/";
document.forms[0].T1.value = month + s + day + s + year;
-->
</script>

To fromat it to the European or ISO date format, change the sequence in
the last assignemnt for that format.

...PC
 
P

p c

A better solution is to not assign the date at the form but get at the
server on the processing page and add it to the database along with the
other fields.

Advantages:
* date is consisted because it is based on the server's time zone. The
date based on client can vary based on the client's time zone.
* date not be set if the user disables javasdctipt on the lient.

But you must do it in code (ASP, php etc) --not w/FP (FPSE)
in ASP w/vbscript
date() gets you the current date
e.g., mm/dd/yyyy
now() gets you the time as date and time
e.g., mm/dd/yyyy hh:mm:ss am/pm

...PC
 

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

Top