chrøma
Epic Fail Analyst
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
200 XP
In this tutorial we will create a Simple User Review Rating using JavaScript. This code will display the user review when the user submit the input form. The code use onclick() function to launch a specific function that apply a animated rating star that created using sessionStorage that temporary store a data and for() loop in order to loop the star 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 display user review when the button is clicked. 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 Simple User Review Rating 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"
/
>
- <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"
>
Sourcecodester</
a
>
- </
div
>
- </
nav>
- <div
class
=
"col-md-3"
></
div
>
- <div
class
=
"col-md-6 well"
>
- <h3
class
=
"text-primary"
>
JavaScript - Simple User Review Rating</
h3
>
- <hr
style
=
"border-top:1px dotted #ccc;"
/
>
- <div
class
=
"col-md-4"
>
- <div
class
=
"form-group"
>
- <label
>
User:</
label
>
- <input
type
=
"text"
id
=
"user"
class
=
"form-control"
/
>
- </
div
>
- <div
>
- <h3
>
Rating:</
h3
>
- <span
id
=
"1"
style
=
"font-size:30px; cursor:pointer;"
class
=
"fa fa-star"
onmouseover
=
"startRating(this)"
startRating=
"starmark(this)"
></
span
>
- <span
id
=
"2"
style
=
"font-size:30px; cursor:pointer;"
class
=
"fa fa-star"
onmouseover
=
"startRating(this)"
startRating=
"starmark(this)"
></
span
>
- <span
id
=
"3"
style
=
"font-size:30px; cursor:pointer;"
class
=
"fa fa-star"
onmouseover
=
"startRating(this)"
startRating=
"starmark(this)"
></
span
>
- <span
id
=
"4"
style
=
"font-size:30px; cursor:pointer;"
class
=
"fa fa-star"
onmouseover
=
"startRating(this)"
startRating=
"starmark(this)"
></
span
>
- <span
id
=
"5"
style
=
"font-size:30px; 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
=
"submitRate()"
>
Submit</
button
></
center
>
- </
div
>
- <div
class
=
"col-md-6"
>
- <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 user review when the button is clicked. 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
- var
rate =
0
;
- function
submitRate(
)
{
- var
user=
document.getElementById
(
'user'
)
.value
;
- var
review=
document.getElementById
(
'review'
)
.value
;
- if
(
rate !=
0
&&
user !=
""
&&
review !=
""
)
{
- var
html=
- "<h4>User: <label class='text-primary'>"
+
user +
"</label></h4>"
- +
"<h4>Rating: <label class='text-primary'>"
+
rate +
"</label></h4>"
- +
"<h4>Review</h4>"
- +
"<p>"
+
review+
"</p>"
- +
"<hr style='border-top:1px solid #000;'/>"
;
- document.getElementById
(
'result'
)
.innerHTML
+=
html;
- document.getElementById
(
'user'
)
.value
=
""
;
- document.getElementById
(
'review'
)
.value
=
""
;
- }
- }
- function
startRating(
item)
{
- rate=
item.id
[
0
]
;
- sessionStorage.star
=
rate;
- for
(
var
i=
0
;
i<
5
;
i++
)
{
- if
(
i<
rate)
{
- document.getElementById
(
(
i+
1
)
)
.style
.color
=
"yellow"
;
- }
- else
{
- document.getElementById
(
(
i+
1
)
)
.style
.color
=
"black"
;
- }
- }
- }
There you have it we successfully created a Simple User Review Rating 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 the hidden content.