abo88
Haha Hero
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
400 XP
In this tutorial we will create a Simple Star Rating using JavaScript. 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 the capabilities of Object-Oriented.
So Let's do the coding...
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. This code will render application and display the form. 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 display the review and rating of the users. To do this just copy write the code as shown below inside the text editor and save it as script.js
.
There you have it we successfully created a Simple Star Rating using JavaScript. I hope that this very simple tutorial helps you to what you are looking for. For more updates and tutorials just kindly visit this site.
Demo
Enjoy Coding!!
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
Download
So Let's do the coding...
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. This code will render application and display the form. 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"
/
>
- <link
rel
=
"stylesheet"
type
=
"text/css"
href
=
"fontawesome/css/all.css"
/
>
- </
head
>
- <body
>
- <nav class
=
"navbar navbar-default"
>
- <div
class
=
"continer-fluid"
>
- <a
class
=
"navbar-brand"
href
=
"https://sourcecodester.com"
target
=
"_blank"
>
Sourcecodester</
a
>
- </
div
>
- </
nav>
- <div
class
=
"col-md-3"
></
div
>
- <div
class
=
"col-md-6 well"
>
- <h3
class
=
"text-primary"
>
JavaScript - Simple Star Rating</
h3
>
- <hr
style
=
"border-top:1px dotted #ccc;"
/
>
- <div
class
=
"col-md-3"
></
div
>
- <div
class
=
"col-md-6"
>
- <div
>
- <h3
>
Rating:</
h3
>
- <span
id
=
"1"
style
=
"font-size:45px; cursor:pointer;"
class
=
"fa fa-star"
onmouseover
=
"startRating(this)"
startRating=
"starmark(this)"
></
span
>
- <span
id
=
"2"
style
=
"font-size:45px; cursor:pointer;"
class
=
"fa fa-star"
onmouseover
=
"startRating(this)"
startRating=
"starmark(this)"
></
span
>
- <span
id
=
"3"
style
=
"font-size:45px; cursor:pointer;"
class
=
"fa fa-star"
onmouseover
=
"startRating(this)"
startRating=
"starmark(this)"
></
span
>
- <span
id
=
"4"
style
=
"font-size:45px; cursor:pointer;"
class
=
"fa fa-star"
onmouseover
=
"startRating(this)"
startRating=
"starmark(this)"
></
span
>
- <span
id
=
"5"
style
=
"font-size:45px; cursor:pointer;"
class
=
"fa fa-star"
onmouseover
=
"startRating(this)"
startRating=
"starmark(this)"
></
span
>
- </
div
>
- <br
/
>
- <div
class
=
"form-group"
>
- <h3
>
Review:</
h3
>
- <textarea
id
=
"review"
class
=
"form-control"
style
=
"resize:none; height:100px;"
></
textarea
>
- </
div
>
- <center
><button
class
=
"btn btn-success"
onclick
=
"result()"
>
SUBMIT</
button
></
center
>
- <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 display the review and rating of the users. To do this just copy write the code as shown below inside the text editor and save it as script.js
.
- var
count =
0
;
- function
result(
)
{
- if
(
count !=
0
)
{
- document.getElementById
(
'result'
)
.innerHTML
=
- "<h4>Rating: <label class='text-primary'>"
+
count +
"</label></h4>"
- +
"<h4>Review</h4>"
- +
"<p>"
+
document.getElementById
(
"review"
)
.value
+
"</p>"
;
- }
else
{
- }
- }
- function
startRating(
item)
{
- count=
item.id
[
0
]
;
- sessionStorage.star
=
count;
- for
(
var
i=
0
;
i<
5
;
i++
)
{
- if
(
i <
count)
{
- document.getElementById
(
(
i+
1
)
)
.style
.color
=
"yellow"
;
- }
- else
{
- document.getElementById
(
(
i+
1
)
)
.style
.color
=
"black"
;
- }
- }
- }
There you have it we successfully created a Simple Star Rating using JavaScript. I hope that this very simple tutorial helps you to what you are looking for. For more updates and tutorials just kindly visit this site.
Demo
Enjoy Coding!!
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
Download
You must upgrade your account or reply in the thread to view hidden text.