I am Asif Khalyani. I am software Engineer. PHP and ajax free script download site phpasks. User can download ajax rating script
Introduction
Frequent visitors of ajax enabled websites, like ajaxian, have all witnessed them already: ajax rating widgets. They are flashy, animated, you can use them to rate the content (usually without refreshing the page) and if you could, you'd present them to your parents and marry them. Compared to the classic rating system, as on IMDb, they incite people to click them, reducing the effective rating process to only one click.
In this tutorial, I want to show you how to create the JavaScript framework to display the animated rating widget and how to connect it to your server backend by using some of the most common Ajax frameworks out there. I clearly separate the page creation from the JavaScript functions and the rating backend, to allow the script to be as flexible as possible and to be easy integrable into your existing website.
This tutorial is not meant to present you with a finished script (even though you could simply copy&paste the end result into your website and make it work without any problems), but rather to explain the design and implementation process that would enable you to create your own widgets if you'd need to. Getting started with the HTML markup
What It Is
This is a rating bar script done with PHP and mySQL that allows users to rate things like can be done all web 2.0-like with no page refresh. It is a major improvement on the previous version because it is now unobtrusive, meaning that if Javascript is off it will still work (although the page will refresh). You can also set the number of rating units you want to use (i.e. 4 stars, 5 stars, or 10 stars) on a rater to rater basis (see samples below or read the docs). A few other changes were made as well see the docs for details. Note that this script isnt tied to any specific system (such as WordPress), so you should be able to adapt it to your situation without too much trouble. What are you waiting for? Check the Ajax Rating demos.
It is most important that there are no line breaks in this code, as this will complicate the DOM tree unnecessarily. If you are uncertain about what I just said, please read the W3Schools HTML DOM Tutorial for further reference, since we are going to access the DOM directly from within our JavaScript.
As you can see, the div container is pretty easy to generate in the server-side scripting language, requiring most of the time only one line:
printf("%s", ratingId, rating);
The "continue" keyword in our JavaScript code, just like in most other programming languages, continues with the next iteration of the loop and prevents the execution of the rest of the code during that iteration. Read the rating value
Now that we have all the rating containers, we can start by reading the rating value written as text inside the div container. To read that value, we access the first child node of the div container, which is a TextNode, and access its nodeValue, which returns the text CDATA in case of text nodes. This is done by the following line:
var rating = ratings[i].firstChild.nodeValue;
There is no graceful way to recover from that error, so I simply decided to continue with the next rating container and prevent that error from happening within the server backend.
Now, we need to loop over the number of stars that are displayed and check what the image graphic will be that is displayed on the star. Using the HTML DOM function createElement(), we initialize a new image and progressively add the respective values to that element. Of course, the first thing we are interested in is the displayed image: we could either test the rating against the current iteration value or we could decrement the rating value during each iteration and test against 1, 0.5 and 0. I decided to decrement the rating during each iteration, which presents me with three simple cases to test: if the rating is greater than or equal than 1, the star is "on", if the rating is exactly 0.5, the star is "half" otherwise, the star is "off". This results in the following code:
for (var j = 0; j < NUMBER_OF_STARS; j++)
{
var star = document.createElement('img');
if (rating >= 1)
{
star.setAttribute('src', './images/stars/rating_on.gif');
rating--;
}
else if(rating == 0.5)
{
star.setAttribute('src', './images/stars/rating_half.gif');
rating = 0;
}
else
{
star.setAttribute('src', './images/stars/rating_off.gif');
}
ratings[i].appendChild(star);
}
Conclusion
Our current JavaScript allows us to transform specially marked div containers into animated rating widgets that we can use in specialized Ajax frameworks to link to our server backend. The HTML markup is completely separated from the JavaScript code, which will leave the user with a not very stylish but still visual display of the current rating in case JavaScript is disabled. I've put together a ZIP file with the current result, containing an HTML file, a CSS file, the JavaScript file and the images. Connect the widget to the server with different frameworks
Please make sure to delete the "window.onload=init_rating;" line in the "script.js" file if you downloaded the .zip file, since we're using the specialized framework onload event.
The examples below are only an illustration of how this given task is achievable with a variety of different JavaScript frameworks. It should not be used as a reference about what framework is superior since not every framework follows the same route and has the same objectives. Before jumping to conclusion, you should read more sources and also hear every site. There are good reasons for dojo not having the $ operator and some interesting points can be found here (in the comments). When you need to decide which framework to chose, base your decision on your specific task and the framework you're most comfortable with. The PHP backend
- Related Videos
- Related Articles
- Ask / Related Q&A




php software development company
By: usha sharma | 08/07/2009Professional Web Development Company phpmaestro provides custom website development web application development ecommerce website design and development services. Custom web application development services and professional website development at affordable rates from phpmaestro Company. www.phpmaestro.com is a php Application Development Shopping Cart for e-commerce stores. Our shopping cart software gives our client full control over your online shop its products design development prices sh
Hire ASP .Net Developers Hire Dedicated ASP.Net Developers Offshore ASP.Net Programmers
By: Arshad | 08/07/2009Since the concept of outsourcing changed the economy of many countries it has been very clear that paying Indian development service providers is very much economical than funding an in-house private team. Analysis says that more than 50% of the cost can be saved by inking contracts with Indian IT service providers.
Windbg Minidump Tutorial:Setting up & Reading Minidump Files
By: Jeannie Lee | 07/07/2009Windgb Minidump tutorial to set up and read minidump files (.dmp). Setting Symbol File Path. Output of Windbg command. windbg.exe -z [file path to minidump file.dmp] -c !analyze -v.
Javascript Validate Name Field
By: Jeannie Lee | 07/07/2009Simple Javascript tutorial on validating a name field. Checks to see if there is a value in the name field with Javascript after the user submits a form.
Logo Design- The image creator!
By: Jhonny Sharma | 07/07/2009Brand image is something that many consumers look for while buying a product. Brand image and brand positioning have become important concepts in the corporate world. When image building strategies are talked about, what tops the list is a creative logo design.
Design principles in logo
By: Jhonny Sharma | 07/07/2009An element of balance is a mandatory aspect of design. A design is considered to be a great design when it incorporates all design aspects in the required proportion. The design principles are vital for any kind of design.
Organization specific software
By: Manish Shrivastava | 07/07/2009Different businesses have different technological needs depending upon the type of work they are engaged in. Some businesses might require minimum use of software technology where there might be others whose very business might depend upon the optimum use of technology.
Hire .Net Developers: Hire ASP.Net Programmers
By: Arshad | 07/07/2009Since the concept of outsourcing changed the economy of many countries it has been very clear that paying Indian development service providers is very much economical than funding an in-house private team. Analysis says that more than 50% of the cost can be saved by inking contracts with Indian IT service providers.
Easy Ajax Inline Text Edit 2.0
By: Asif Khalyani | 09/09/2008 | ProgrammingA small piece of javascript reads al SPAN tags, checks if it has class="editText" and a id=. If that is true, it adds a onclick function. That onclick function will create a textfield or input (depending on the size of the editable text). Someone has the ability to edit the field. When the text field is blurred, it will read the contents, and starts a XMLHttpRequest and ‘sends’ the content + fieldname + any set vars to an update file.
Ajax Rating Script - Php & Mysql
By: Asif Khalyani | 09/09/2008 | ProgrammingFrequent visitors of ajax enabled websites, like ajaxian, have all witnessed them already: ajax rating widgets.
Ajax Form Validation and Thread-safe Ajax
By: Asif Khalyani | 03/07/2008 | ProgrammingThis is the PHP and AJAX form validation application you can create AJAX and PHP: Building Responsive Web Applications.
Upload Image Without Refresh Page - Asynchronous Image File Upload Without Ajax
By: Asif Khalyani | 23/06/2008 | ProgrammingI suppose it is neccessary to bring a little bad news to Ajax at this point, it is not possible to process a file upload through the XMLHtrtpRequest Object. The reason of this is that javascript has no access to your computer's file system.