/    Sign up×
Community /Pin to ProfileBookmark

Desperate help needed

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

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@havikMar 31.2003 — 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
Copy linkTweet thisAlerts:
@havikMar 31.2003 — 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
Copy linkTweet thisAlerts:
@dgroverauthorMar 31.2003 — 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>
Copy linkTweet thisAlerts:
@havikApr 01.2003 — 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>
×

Success!

Help @dgrover spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...