zombiebebop31
Reverse Engineer
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
500 XP
In this tutorial we will create a Change List By Drop Down using JavaScript. This code will dynamically change the list base from the selection of the select tag when the change the options. The code use onchange() to call a function that change a list base from the options of select tag using switch conditional statement, that will display a different list when the statement meet the required value. You can apply this script to your code to make your transaction faster, it is a user-friendly program feel free to modify it.
We will use JavaScript to add some new feature to the website interface by actually written into an HTML page. It is what gives your page a different interactive elements and animation that engage a user.
Getting Started:
This is the link for the bootstrap that i used for the layout design 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 Script
This code contains the script of the application. This code will change a list base from options in select tag. To do this just copy and write these block of codes as shown below inside the text editor and save it as script.js inside the js directory
There you have it we successfully created a Change List By Drop Down 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
We will use JavaScript to add some new feature to the website interface by actually written into an HTML page. It is what gives your page a different interactive elements and animation that engage a user.
Getting Started:
This is the link for the bootstrap that i used for the layout design 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 - Change List By Drop Down</
h3
>
- <hr
style
=
"border-top:1px dotted #ccc;"
/
>
- <div
class
=
"col-md-3"
>
- <div
class
=
"form-inline"
>
- <label
>
Select an Item</
label
>
- <select
onchange
=
"changeList(this.value);"
class
=
"form-control"
>
- <option
value
=
"math"
>
Math</
option
>
- <option
value
=
"english"
>
English</
option
>
- <option
value
=
"science"
>
Science</
option
>
- </
select
>
- </
div
>
- </
div
>
- <div
class
=
"col-md-9"
>
- <div
id
=
"result"
></
div
>
- </
div
>
- </
div
>
- <script
src
=
"js/script.js"
></
script
>
- </
body
>
- </
html
>
Creating the Script
This code contains the script of the application. This code will change a list base from options in select tag. To do this just copy and write these block of codes as shown below inside the text editor and save it as script.js inside the js directory
- function
changeList(
item)
{
- switch
(
item)
{
- case
"math"
:
- var
member=
[
"John Pratz"
,
"Carl Benon"
]
;
- var
html=
""
;
- html+=
"<h4>Math Student:</h4><br />"
;
- html+=
"<ul>"
;
- for
(
var
i=
0
;
i<
member.length
;
i++
)
{
- html+=
"<li>"
+
member[
i]
+
"</li>"
;
- }
- html+=
"</ul>"
;
- document.getElementById
(
"result"
)
.innerHTML
=
html;
- break
;
- case
"english"
:
- var
member=
[
"Loki Odinson"
,
"Peter Parker"
,
"Claire Temple"
]
;
- var
html=
""
;
- html+=
"<h4>English Student:</h4><br />"
;
- html+=
"<ul>"
;
- for
(
var
i=
0
;
i<
member.length
;
i++
)
{
- html+=
"<li>"
+
member[
i]
+
"</li>"
;
- }
- html+=
"</ul>"
;
- document.getElementById
(
"result"
)
.innerHTML
=
html;
- break
;
- case
"science"
:
- var
member=
[
"Roman Atkinson"
,
"Steve Roger"
,
"Natasha Romanof"
,
"Bruce Banner"
,
"Stephen Strange"
]
;
- var
html=
""
;
- html+=
"<h4>Science Student:</h4><br />"
;
- html+=
"<ul>"
;
- for
(
var
i=
0
;
i<
member.length
;
i++
)
{
- html+=
"<li>"
+
member[
i]
+
"</li>"
;
- }
- html+=
"</ul>"
;
- document.getElementById
(
"result"
)
.innerHTML
=
html;
- break
;
- }
- }
There you have it we successfully created a Change List By Drop Down 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.