PDA

View Full Version : Javascript - tooltips?



vegasidol
02-10-2010, 05:32 PM
I have a javascript that displays a 'rating system' and the tooltips display "1, 2, 3" based upon a calculation over which star (rating) you hover. I want to change the custom display of each star to be 'Good, Better, Best' but this script is beyond me. Anyone?




var displayRating = '';
var currentId = '';
var root = '';

function Rate(obj, rating) {
var id = obj.title;
var fullId = obj.id;
var idName = fullId.substr(0, fullId.indexOf('_'));
window.location = root+'ratepic.php?rate='+id+'&pic='+idName;
}

function changeover(obj, rating) {

var imageName = obj.src;
var id = obj.title;
var index = imageName.lastIndexOf('/');
var filename = imageName.substring(index+1);
var fullId = obj.id;
var idName = fullId.substr(0, fullId.indexOf('_'));
var totalRating = rating;

for(i=0; i<id; i++) {
var num = i+1;

document.getElementById(idName+'_'+num).src = 'images/new.gif';
}

}

function changeout(obj, rating) {

var imageName = obj.src;
var id = obj.title;
var index = imageName.lastIndexOf('/');
var filename = imageName.substring(index+2);
var fullId = obj.id;
var idName = fullId.substr(0, fullId.indexOf('_'));
var totalRating = rating;

for(i=0; i<id; i++) {
var num = i+1;

if(i < totalRating) {
document.getElementById(idName+'_'+num).src = 'images/full.gif';
}
else {
document.getElementById(idName+'_'+num).src = 'images/empty.gif';
}
}
}

function displayStars(rating, idName, url) {
root = url;
document.write('<center>');

for(i=0; i < 3; i++ ) {
if(i < rating) {
document.write('<img src="images/full.gif" id="'+idName+'_'+(i+1)+'" title="'+(i+1)+'" onmouseout="changeout(this, '+rating+')" onmouseover="changeover(this, '+rating+')" onclick="Rate(this, '+rating+')" />');
}
else {
document.write('<img src="images/empty.gif" id="'+idName+'_'+(i+1)+'" title="'+(i+1)+'" onmouseout="changeout(this, '+rating+')" onmouseover="changeover(this, '+rating+')" onclick="Rate(this, '+rating+')" />');
}
}

document.write('</center>');

}