JavaScript - Simple User Review Rating
Submitted by razormist on Saturday, October 26, 2019 - 14:55.
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.
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!
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">
- </div>
- </nav>
- <div class="col-md-6 well">
- <hr style="border-top:1px dotted #ccc;"/>
- <div class="col-md-4">
- <div class="form-group">
- <input type="text" id="user" class="form-control" />
- </div>
- <div>
- </div>
- <br />
- <div class="form-group">
- </div>
- </div>
- <div class="col-md-6">
- </div>
- </div>
- </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";
- }
- }
- }
Comments
Add new comment
- Add new comment
- 5192 views