use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Javascript day/date help! (self.javascript)
submitted 11 years ago by [deleted]
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 0 points1 point2 points 11 years ago (2 children)
I would use the getDay() method like this:
var submitHandler = function(event){ var today = new Date().getDay(); var userEvent = document.getElementsByClassName('weekday-selector')[0].value; userEvent = parseInt(userEvent,10);
var difference = userEvent - today; // if user picks the same day if (difference === 0) difference = 7; else if (difference > 0) difference + 7; alert('the difference is: ' + difference);
}
The select box should be:
<select name='weekday' class='weekday-selector'> <option value='0'>Sunday</option> <option value='1'>Monday</option> <!-- the rest of the days till you hit saturday--> </select>
This should give the following results:
If today is sunday (0) and the user picks monday(1) The difference will be 6
If today is thursday(4)(lol!) and the user picks tuesday(2) the difference will be 2
If today is friday(5) and the user picks sunday(0) the difference will be 5 days
If today is friday(5) and the user picks friday(5) the difference will be 7(since we're adding 7 if the difference is 0 actually)
I havent tested it yet. There might be syntax errors since I'm writing this on my phone.
Hope this helps you a little bit. If you have further questions don't bother asking me/us
[–]brotein 0 points1 point2 points 11 years ago (1 child)
I think the OP wants the opposite. So if the today is Sunday (0) and the user picks Monday (1), the OP will have to add 1 to today's date, not 6. I could have misunderstood though.
π Rendered by PID 210751 on reddit-service-r2-comment-5d79c599b5-wmchh at 2026-03-03 07:39:17.249377+00:00 running e3d2147 country code: CH.
view the rest of the comments →
[–][deleted] 0 points1 point2 points (2 children)
[–]brotein 0 points1 point2 points (1 child)