Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setting the date in a form 3

Status
Not open for further replies.

Rupa

Programmer
Jun 7, 2002
19
US

does anyone know how to automatically set the date in a form?

i have a form where one of fields is date and i want it to automatically show that day's date either when the page loads or when the field has focus. i need the function for the date but i want it either in 01-01-01 or 01/01/01 with no time or anything else.

thanks!!

rupa [ponytails2]
 
<html>
<body>

<script type=&quot;text/javascript&quot;>
var d = new Date()
document.write(d.getDate())
document.write(&quot;/&quot;)
document.write(d.getMonth() + 1)
document.write(&quot;/&quot;)
document.write(d.getFullYear())
</script>

</body>
</html> ---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
You can't get the 2-date year now (since the browsers return it as 102 instead of 02)...
This is what I use:

<SCRIPT>
var mydate=new Date()
var theYear=mydate.getFullYear()

var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
daym=&quot;0&quot;+daym
var montharray=new Array(&quot;01&quot;,&quot;02&quot;,&quot;03&quot;,&quot;04&quot;,&quot;05&quot;,&quot;06&quot;,&quot;07&quot;,&quot;08&quot;,&quot;09&quot;,&quot;10&quot;,&quot;11&quot;,&quot;12&quot;)
document.write(&quot;<font face='Geneva, Arial, Helvetica, san-serif'><h6>   &quot;+montharray[month]+&quot;/&quot;+daym+&quot;/&quot;+theYear+&quot;</h6></font>&quot;)
</SCRIPT>
I have not failed; I merely found 100,000 different ways of not succeding...
 
Wow talk about quick response! [surprise]

i noticed that you put that script in the body....it doesn't need to be in the head?? also, i want it written to a text field named Last_Issue_Date. would i do it like this:

<input type=&quot;text&quot; name=&quot;last_issue_date&quot; onFocus=&quot;myDate()&quot;>

and then put the above script in a function called my date like this:

<script type=&quot;text/javascript&quot;>

function myDate(){
var d = new Date()
document.last_issue_date.value.write(d.getDate())
document.last_issue_date.value.write(&quot;/&quot;)
document.last_issue_date.value.write(d.getMonth() + 1)
document.last_issue_date.value.write(&quot;/&quot;)
document.last_issue_date.value.write(d.getFullYear())

</script>
or is this wrong?

thanks a ton! [ponytails2]
 
thanks, gujuModel....what up? [smile]

hey, how do i call that script from my text box??

btw,

i checked out your webpage quickly....i saw a link to it on here when i was searchin for some other info.....it looks really good....more about that later....gotta get this done before 5 and that only leaves me 1/2 an hour
 
try this to load it into the text from the onLoad
<html>
<head>
<script type=&quot;text/javascript&quot;>
function date(){
var d = new Date()
var e = (d.getDate())
var e = e + (&quot;/&quot;)
var e = e + (d.getMonth() + 1)
var e = e + (&quot;/&quot;)
var e = e + (d.getFullYear())
alert(&quot;time &quot; + e);
document.form1.date.value = e;
}
</script>
</head>
<body onLoad=&quot;date()&quot;>
<form name=&quot;form1&quot;>
<input type=&quot;text&quot; name=&quot;date&quot;>
</form>
</body>
</html> I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
 
NEVERSLEEP
Hope I didn't step on toes modifying your code. I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
 
yaaaaaaaaay!

you guys rock! [smile]

it works!!! thanx!
 
A slight modification to your code onpnt...

<html>
<head>
<script type=&quot;text/javascript&quot;>
function date(){
var d = new Date()
var e = (d.getDate())
var e = e + (&quot;/&quot;)
var e = e + (d.getMonth() + 1)
var e = e + (&quot;/&quot;)
var e = e + (d.getFullYear())
//alert(&quot;time &quot; + e);
document.form1.date.value = e;
}
</script>
</head>
<body onLoad=&quot;date()&quot;>
<form name=&quot;form1&quot;>
<input type=&quot;text&quot; name=&quot;date&quot;>
</form>
</body>
</html>

I took out the portion in bold becuase that will throw an alert and then populate the textbox...I don't think Rupa wanted an alert box first... I have not failed; I merely found 100,000 different ways of not succeding...
 
then give a star to onpnt [thumbsup2] ---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
I did that to test it and forgot to get rid of it.
Sharp eye's
I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
 
yah, i saw that and i took it out.....
i got it goin already....thanks!!
 
you did all the work NEVERSLEEP you deserve the star I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
 

you guys all get stars from me!

rupa [ponytails2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top