Abood000
DevOps Pipeline Architect
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
300 XP
In this tutorial we will create a Display Week Days From A Given Datet using JavaScript. This code will generate a list of days in a week when user provide a input date. The code use onclick() to call a function that display a list of days using for loop to rearrange the index position of arrays to form a group of weekdays. This a free program feel free to modify it and use it in your system.
JavaScript is a scripting or programming language that allows you to implement complex things on web pages. It is widely used in designing a stunning website. It is an interpreted programming language that has a capabilities of Object-Oriented.
Getting started:
This is the link for the bootstrap that has been used for the layout of the calculator https://getbootstrap.com/.
The Main Interface
This code contains the interface of the application. To create this just write these block of code inside the text editor and save this as index.html.
Creating the Main Function
This code contains the main function of the application. This code will display a list of days in a week when the button is clicked. To do this just copy and write these block of codes as shown below inside the text editor then save it as script.js inside the js folder.
There you have it we successfully created a Display Week Days From A Given Date using JavaScript. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!
Download
JavaScript is a scripting or programming language that allows you to implement complex things on web pages. It is widely used in designing a stunning website. It is an interpreted programming language that has a capabilities of Object-Oriented.
Getting started:
This is the link for the bootstrap that has been used for the layout of the calculator https://getbootstrap.com/.
The Main Interface
This code contains the interface of the application. To create this just write these block of code inside the text editor and save this as index.html.
- <!DOCTYPE html>
- <html
lang
=
"en"
>
- <head
>
- <meta
charset
=
"UTF-8"
name
=
"viewport"
content
=
"width=device-width, initial-scale=1"
/
>
- <link
rel
=
"stylesheet"
type
=
"text/css"
href
=
"css/bootstrap.css"
/
>
- </
head
>
- <body
>
- <nav class
=
"navbar navbar-default"
>
- <div
class
=
"container-fluid"
>
- <a
class
=
"navbar-brand"
href
=
"https://sourcecodester.com"
>
Sourcecodester</
a
>
- </
div
>
- </
nav>
- <div
class
=
"col-md-3"
></
div
>
- <div
class
=
"col-md-6 well"
>
- <h3
class
=
"text-primary"
>
JavaScript - Display Week Days From A Given Date</
h3
>
- <hr
style
=
"border-top:1px dotted #ccc;"
/
>
- <div
class
=
"col-md-4"
>
- <form
>
- <div
class
=
"form-group"
>
- <label
>
Enter A Date</
label
>
- <input
type
=
"date"
id
=
"date"
class
=
"form-control"
/
>
- <br
/
>
- <center
><button
type
=
"button"
onclick
=
"getWeekDays();"
class
=
"btn btn-primary"
><span
class
=
"glyphicon glyphicon-save"
></
span
>
Submit</
button
></
center
>
- </
div
>
- </
form
>
- </
div
>
- <div
class
=
"col-md-8"
>
- <div
id
=
"result"
></
div
>
- </
div
>
- </
div
>
- </
body
>
- <script
src
=
"js/script.js"
></
script
>
- </
html
>
Creating the Main Function
This code contains the main function of the application. This code will display a list of days in a week when the button is clicked. To do this just copy and write these block of codes as shown below inside the text editor then save it as script.js inside the js folder.
- function
dayInAWeek(
date)
{
- var
days =
new
Array
(
)
;
- for
(
var
i =
0
;
i <
7
;
i++
)
{
- days[
i]
=
new
Date
(
date.getFullYear
(
)
,
date.getMonth
(
)
,
date.getDate
(
)
-
date.getDay
(
)
+
1
+
i)
;
- }
- return
days;
- }
- function
getWeekDays(
)
{
- var
date =
document.getElementById
(
'date'
)
;
- if
(
date.value
==
""
)
{
- alert(
"Please enter a something first!"
)
;
- }
else
{
- var
months=
[
"January"
,
"February"
,
"March"
,
"April"
,
"May"
,
"June"
,
"July"
,
"August"
,
"September"
,
"October"
,
"November"
,
"December"
]
;
- var
days =
[
'Sunday'
,
'Monday'
,
'Tuesday'
,
'Wednesday'
,
'Thursday'
,
'Friday'
,
'Saturday'
]
;
- var
newDate =
new
Date
(
date.value
)
;
- var
date_array =
new
Array
(
)
;
- date_array =
dayInAWeek(
newDate)
;
- var
data =
"<h2>Week Days</h2>"
;
- for
(
var
i=
0
;
i <
date_array.length
;
i++
)
{
- data +=
"<ul><li>"
+
days[
date_array[
i]
.getDay
(
)
]
+
": "
+
months[
date_array[
i]
.getMonth
(
)
]
+
" "
+
date_array[
i]
.getDate
(
)
+
", "
+
date_array[
i]
.getFullYear
(
)
+
"</li></ul>"
;
- }
- document.getElementById
(
'result'
)
.innerHTML
=
data;
- }
- }
There you have it we successfully created a Display Week Days From A Given Date using JavaScript. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!
Download
You must upgrade your account or reply in the thread to view hidden text.