How do I add in a javascript to a form object

D

dusty

I have a form text box where users will add the date in. I have been looking
around for a script that will automatically put in the current date (I'll
find something, of course suggestions are always welcome). Once I find a
javascript that displays the current date how do I get it to input this into
the form object??

hopefully this makes sense to someone..

Thanks.
 
M

MD Websunlimited

Hi Dusty,

You may wish to take a look at J-Bots DatePicker to allow the user to select a date but if all you want is the current date then
<script>
function shortDate() {

oDate = new Date();

month = oDate.getMonth();

year = oDate.getFullYear();

day = oDate.getDate();

return month + 1 + '/' + day + '/' + year;

}

</script>

<body onload="document.theform.thefield.value = shortDate();" >

Date Picker --> http://www.websunlimited.com/order/Product/DatePicker/datepicker.htm
--
Mike -- FrontPage MVP '97-'02
J-Bots 2004 102 Components For FP
http://www.websunlimited.com
FrontPage Add-ins Since '97 FP 2003 / 2002 / 2000 Compatible
Download the Trial http://www.microsoft.com/frontpage/downloads/addin/launchupdate/download.asp
 
D

dusty

Sorry for the late response.. I have been stuck at a client site all week
working on a tough project..

I am not looking for a date selector (like on expedia).. just a script that
puts todays date into a form field by default.. the script below.. how do I
add that to a form field.. ?? Sorry I don't know anything about
Javascripting... Plus the script looks like it might have some problems.. is
this right?? <script>
 
T

Trevor L.

A beginner in this field also. Let's see if I can help.

What you need to do is to name the form "theform" and name the field
"thefield" and place code in the onload=

<head>
.....
<script>
function shortDate() {
oDate = new Date();
month = oDate.getMonth();
year = oDate.getFullYear();
day = oDate.getDate();
return month + 1 + '/' + day + '/' + year; }
</script>
</head>
<body onload="document.theform.thefield.value = shortDate();" >
<form name="theform">
<input type="text" name="thefield" value="">
</form>
.....
--
Cheers,
Trevor L.
Website: http://tandcl.homemail.com.au

dusty said:
Sorry for the late response.. I have been stuck at a client site all week
working on a tough project..

I am not looking for a date selector (like on expedia).. just a script
that
puts todays date into a form field by default.. the script below.. how do
I
add that to a form field.. ?? Sorry I don't know anything about
Javascripting... Plus the script looks like it might have some problems..
is
this right?? <script>


I choose Polesoft Lockspam to fight spam, and you?
http://www.polesoft.com/refer.html
 

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