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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is wrong: document.Date.TodayDate.value...doesn't work 2

Status
Not open for further replies.

Nogi

Technical User
Dec 10, 2004
132
BE
i've tried to write a simple piece of code, that puts the current date into a textboxfield.

The current date should be written like this : 20062404

This is what i have so far:

Code:
<form name="Date">
<input size=20 maxlength=75 type='text' name='TodayDate' value=""></form>
<script language="JavaScript" type="text/javascript">
var date = new Date();
var d  = date.getDate();
var day = (d < 10) ? '0' + d : d;
var m = date.getMonth() + 1;
var month = (m < 10) ? '0' + m : m;
var yy = date.getYear();
var year = (yy < 1000) ? yy + 1900 : yy;
document.Date.TodayDate.value.(year + month + day);
</script>

I also tried :
Code:
document.Date.TodayDate.value=(year + month + day);

But that didn't work ether. I can't be to far away from a solution, i hope lol.

Who could help me out with this please?

Thanks in advance
 
Date is reserved.
>[tt]<form name="Date">[/tt]
[tt]<form name="[blue]f[/blue]Date"><!-- or whatever other than Date -->[/tt]
and consequently
[tt]document.[blue]f[/blue]Date.TodayDate.value=(year + month + day);[/tt]
 
Still doesn't work somehow...

This is what i have now:
Code:
<form name="TDate">
<input size=20 maxlength=75 type='text' name='TodayDate' value=""></form>
<script language="JavaScript" type="text/javascript">
var date = new Date();
var d  = date.getDate();
var day = (d < 10) ? '0' + d : d;
var m = date.getMonth() + 1;
var month = (m < 10) ? '0' + m : m;
var yy = date.getYear();
var year = (yy < 1000) ? yy + 1900 : yy;
document.TDate.TodayDate.value=(year + month + day);
</script>

Any ideas?
 
>Still doesn't work somehow...
You must have a broken/out-of-common browser! I won't response to that. You test it more carefully.

As an aside, you can improve the year-bit. But it is not the problem.
[tt]//var yy = date.getYear();
//var year = (yy < 1000) ? yy + 1900 : yy;
var year=date.getFullYear();
[/tt]
 
Nogi, this code works for me.
Code:
<form name="fDate">
<input size=20 maxlength=75 type='text' name='TodayDate' value=""></form>
<script language="JavaScript" type="text/javascript">
var date = new Date();
var d  = date.getDate();
var day = (d < 10) ? '0' + d : d;
var m = date.getMonth() + 1;
var month = (m < 10) ? '0' + m : m;
var yy = date.getYear();
var year = (yy < 1000) ? yy + 1900 : yy;
document.fDate.TodayDate.value=(year + month + day);
</script>
It is your code with tsuji's suggested change to the form name and your alternate method of writing the value to the form field so it is not anything new.
The line: document.Date.TodayDate.value.(year + month + day);
is invalid and will not work. I suspect you may have made the changes to the form name that tsuji suggested but still had the invalid line for inserting the value.

NOTE: You said you wanted the date field to show as 20062404 which would be Year, Day, Month but your code is setting it as Year, Month, Day which comes out 20060424.

If the above code does not work for you then let us know what browser you are using.


Paranoid? ME?? Who wants to know????
 
i'm aware that the code must work. If you check my last posting, you see that i did change the last lign in the code to the correct way.

To give you a little bit more information. The html page this code has to work on, is generated by a webfocus report. Webfocus is some sort of a reporting platform for business applications.

The actual html is:
Code:
<input size=20 maxlength=75 type='text' name='TodayDate' value="">

So actually, i don't have anything but the textbox in my html.

What i did was manually add the [FORM Name="TDate"] and [/FORM] around the textboxcode in the html-source, in order to get the javascript value in the textbox.

Problem is that with the form-brackets around it, my report doens't work anymore, since webfocus didn't generate them in the html in the first place.

Might be difficult to understand, but it all comes down to this: If i use [form] and [/form], my html will not function anymore.

I must find another way to get the date in the textbox.
 
Then use a more direct method to put the value into the box.
Can you add an ID tag to the field?
<input size=20 maxlength=75 type='text' name='TodayDate' id='TodayDate' value="">

Then you can use this DOM method to add the value:
document.getElementById('TodayDate').value=(year + month + day);

Or if you are in an IE only shop you may be able to use document.all to get around specifying the name of the form in order to reach the form element. But the DOM method above is the best way to go if it works for you.




Paranoid? ME?? Who wants to know????
 
That worked like a charm theniteowl.

Thank you very much for this solution.

Kind regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top