Click to See Complete Forum and Search --> : Desperate help needed


dgrover
03-31-2003, 03:11 PM
Hi
I have aproblem in that I need to enter a date in format dd/mm/yy into a web page text box and on same form another text box should fill out 10 days in furure.

If some one can help me I would be most appreciated.
In vbscript I can do it easily but client side scripting of dates has me beat.
Don

havik
03-31-2003, 03:34 PM
Use this to update it on the fly:

<form name="formname">

<input type=text name="date1" onKeyUp=document.formname.date2.value=this.value>

<input type=text name="date2">

</form>

As for dates, I'll look at this and get back to you

Havik

havik
03-31-2003, 03:39 PM
This works for ten days ago, but I get NaN when I try to get 10 days ahead.

<script language="JavaScript">

today = new Date();
tendays = new Date(today - (10*(24*60*60*1000)));
alert(tendays);

</script>

Change this:
tendaysago = new Date(today - (10*(24*60*60*1000)));

To this to attempt ten days ahead
tendays = new Date(today + (10*(24*60*60*1000)));

(24*60*60*1000) represents a day, so times 10 it represents 10 days.

See if that works for you, maybe I'm doing something wrong.

Havik

dgrover
03-31-2003, 04:04 PM
Thanks havik
I tried it but get the same, I really an desperate but dont have clue about java script.

I have this and it works kind of but does not take into accounts month length and on 2,4,8,11 month it adds a month and 10 days.
I really appreciate your help....


<script type="text/javascript" language="JavaScript">
<!-- HIDE FROM OLD BROWSERS
function validateInput(x){
oldd="Inputstring: "+x+"<br>";
a=x.split('/');

oldy=1*a[2] ;
// 1* makes a numbervalue from a string
if (oldy<35) oldy+=2000;
if (oldy<100) oldy+=1900;
// 1- or 2-number year split at 1935

now=new Date();
now.setFullYear(oldy);
now.setMonth(1*a[1]-1);
// setMonth: Januari=0
now.setDate(a[0]);

thn=new Date(1*now+9*24*60*60*1000);
d=thn.getDate();
m=thn.getMonth()+1;
y=thn.getFullYear();
d=((d<10)?"0":"")+d;
// change 9 to 09
m=((m<10)?"0":"")+m;
s="/";
newd=+d+s+m+s+y;

this.addtransadmin.inputdemurrdate.value=newd;
}
// STOP HIDING -->
</script>

havik
04-01-2003, 09:38 AM
I test the code yesterday and there were problems, today though it runs perfectly. None of the months add a month and ten days and it even accounts for the end of each month, even February. I didn't really change the code at all, I just added a few parenthesis for my own sake and that's all.

If this doesn't work on your computer then something is up with the dates. In this case, it's probably the current date that is messing around with this script somehow.

Havik

<script type="text/javascript" language="JavaScript">
<!-- HIDE FROM OLD BROWSERS
function validateInput(x){
oldd="Inputstring: "+x+"<br>";
a=x.split('/');

oldy=1*a[2] ;

// 1* makes a numbervalue from a string
if (oldy<35) oldy+=2000;
if (oldy<100) oldy+=1900;
// 1- or 2-number year split at 1935

now=new Date();
now.setYear(oldy);
now.setMonth((1 * a[1]) - 1);
// setMonth: Januari=0
now.setDate(a[0]);

thn=new Date((1*now)+(9*24*60*60*1000));
d=thn.getDate();
m=thn.getMonth()+1;
y=thn.getFullYear();
d=((d<10)?"0":"")+d;
// change 9 to 09
m=((m<10)?"0":"")+m;
s="/";
newd=d+s+m+s+y;

alert(newd);
}
// STOP HIDING -->
</script>
</head>

<body>

<a href="#" onclick="validateInput('28/2/03')">test</a>


</body>