PDA

View Full Version : Dates in Text Boxes


Dingbat
10-29-2002, 11:39 AM
Hi Guys,

How can I set the date in a text box automatically when the form is opened?

The Dingbat:confused:

joh6nn
10-29-2002, 12:16 PM
<html>
...
<script>
function makeDate() {
var today = new Date(), temp;
temp = ( today.getMonth() + 1 ) + "/" + today.getDate() + "/" today.getFullYear();
document.theForm.text.value = temp;
}
window.onload = makeDate;
</script>
<body onload="
<form name="theForm">
<input type="text" name="text" value="">
...
</form>
...
</body>
</html>

Dingbat
10-29-2002, 02:25 PM
Hi Joh6nn,

Thanks for your prompt reply. I regret to say that there appears to be something missing in the code that you generated for me.

I have created a new page with only your code in it and I don't get the date in the text box as expected, but I can't see what could be missing. Can I ask you to have another look please?

Regards,

The Dingbat:confused: :confused:

aEr_aEr
10-29-2002, 02:34 PM
there where 2 little fast typing errors

change

temp = ( today.getMonth() + 1 ) + "/" + today.getDate() + "/" today.getFullYear();

with

temp = ( today.getMonth() + 1 ) + "/" + today.getDate() + "/" + today.getFullYear();

reason forgot the +

and change

<body onload="

with

<body>


hope this helps

Dingbat
10-29-2002, 02:52 PM
Thanks for your even more prompt reply. I have modified the code as you suggest and it of course worked. As a novice I couldn't see where the problem lay, I was however able to change your code to the European format to show the date.

Thanks againa for your assisyance. Greatly appreciated.

The Dingbat:thumbsup: :thumbsup: