/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Inserting input variables

[COLOR=”DimGray”]I don’t know Javascript at all, but managed to google my way so far, but now I’ stuck on a simple question of format.

I have two dropdown menus that provides me with Day (1-31) and Month (0-11), and I can get the selected values by writing “results.keys[0]” for Day-, or “results.keys[1]” for the Month-input. From this I am trying to get the Week-number, by using the code below.[/COLOR]

[B]My question is only this: How do I replace the getDay() and getMonth() with my known values “results.keys[X]”? I don’t know the language, and ain’t sure if I should remove the “when.” and “now.” or not, etc. I’ve tried a ton of different ways, but can’t get a result.[/B]

Just a point in the right direction would make me very happy!
Andrew.

[CODE]
<script type=”text/javascript” language=”JavaScript”><!–
function y2k(number) { return (number < 1000) ? number + 1900 : number; }

function getWeek(year,month,day) {
var when = new Date(year,month,day);
var newYear = new Date(year,0,1);
var modDay = newYear.[COLOR=”Red”]getDay()[/COLOR];
if (modDay == 0) modDay=6; else modDay–;

var daynum = ((Date.UTC(y2k(year),when.[COLOR=”Red”]getMonth()[/COLOR],when.[COLOR=”Red”]getDate()[/COLOR],0,0,0) – Date.UTC(y2k(year),0,1,0,0,0)) /1000/60/60/24) + 1;

if (modDay < 4 ) {
var weeknum = Math.floor((daynum+modDay-1)/7)+1;
} else {
var weeknum = Math.floor((daynum+modDay-1)/7);
if (weeknum == 0) {
year–;
var prevNewYear = new Date(year,0,1);
var prevmodDay = prevNewYear.[COLOR=”Red”]getDay()[/COLOR];
if (prevmodDay == 0) prevmodDay = 6; else prevmodDay–;
if (prevmodDay < 4) weeknum = 53; else weeknum = 52;
}
}

return + weeknum;
}

var now = new Date();
document.write(‘Week number = ‘ +
getWeek(y2k(now.getYear()),now.[COLOR=”Red”]getMonth()[/COLOR],now.[COLOR=”Red”]getDate()[/COLOR]));
//–></script>[/CODE]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@AndrewlianauthorFeb 03.2011 — I found another script that does the same, where it was easier to implement the known values to.

[CODE] today = new Date();
thisDay = Date.UTC(2011, results.month, results.days);
thisDay = thisDay / (24 * 60 * 60 * 1000);
thisDay = thisDay - Math.round((2011 - 1970) * 365.25);
offset = 6;
thisDay = thisDay + offset;
thisWeek = Math.round(thisDay / 7) - 1;[/CODE]


Although something is wrong in this, as it gets a few weeks wrong. But with some fine tuning, I'm sure it will do. Sorry about posting before I found this solution, I just needed a quick fix desperately.
×

Success!

Help @Andrewlian 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 5.19,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...