/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] IE problems with a rating script

The following code works in Firefox, Chrome and Opera but not in any flavour of IE:

[CODE]function $(v,o) { return((typeof(o)==’object’?o:document).getElementById(v)); }
function $S(o) { return((typeof(o)==’object’?o:$(o)).style); }
function agent(v) { return(Math.max(navigator.userAgent.toLowerCase().indexOf(v),0)); }
function abPos(o) { var o=(typeof(o)==’object’?o:$(o)), z={X:0,Y:0}; while(o!=null) { z.X+=o.offsetLeft; z.Y+=o.offsetTop; o=o.offsetParent; }; return(z); }
function XY(e,v) { var o=agent(‘msie’)?{‘X’:event.clientX+document.body.scrollLeft,’Y’:event.clientY+document.body.scrollTop}:{‘X’:e.pageX,’Y’:e.pageY}; return(v?o[v]:o); }

star={};

star.mouse=function(e,o) { if(star.stop || isNaN(star.stop)) { star.stop=0;

document.onmousemove=function(e) { var n=star.num;

var p=abPos($(‘star’+n)), x=XY(e), oX=x.X-p.X, oY=x.Y-p.Y; star.num=o.id.substr(4);

if(oX<1 || oX>84 || oY<0 || oY>19) { star.stop=1; star.revert(); }

else {

$S(‘starCur’+n).width=oX+’px’;
$S(‘starUser’+n).color=’#111’;
$(‘starUser’+n).innerHTML=Math.round(parseInt(oX/84*100)/10)*10+’&#37;’;
}
};
} };[/CODE]

This is the code which calls it (I’ve stripped it all out apart from the divs etc):

[CODE]<div>
<div>
<table id=’star’>
<tr>
<td>
<ul id=”star0″ class=”star” onmousedown=”star.update(event,this)” onmousemove=”star.mouse(event,this)” title=”Rate This!”>
<li id=”starCur0″ class=”curr” title=”98″ style=”width: 82px;”></li>
</ul>
<div style=”color: rgb(0, 0, 255);” id=”starUser0″ class=”user”>98%</div>
<br style=”clear: both;”>
</td>[/CODE]

It does however work in IE if called from within the following structure:

[CODE]<div id=”star”>

<ul id=”star0″ class=”star” onmousedown=”star.update(event,this)” onmousemove=”star.mouse(event,this)” title=”Rate This!”>
<li id=”starCur0″ class=”curr” title=”98″ style=”width: 82px;”></li>
</ul>
<div style=”color: rgb(0, 0, 255);” id=”starUser0″ class=”user”>98%</div>
<br style=”clear: both;”>[/CODE]

I’ve spent several days trying to fix the problem with no luck so far so if anyone can suggest what the problem might be I’d be really appreciative.

Ian

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@lxndrauthorSep 15.2010 — Just to add to this I have now managed to make some progress in determining what is causing the problem:

The code is used as part of a rating system which provides a series of 5 blue stars. As the user moves his mouse over them they turn red and a rating value of between 0 and 10 is shown just after the stars.

After several days of getting nowhere in terms of discovering why it won't work in IE I have no discovered that it will work in IE so long as the web page with the rating stars on isn't scrolled down. The moment the page is scrolled the function breaks and won't work again unless I scroll the page back to the top again.

Can anyone suggest if there is something I can do to fix this? Many thanks in advance.
Copy linkTweet thisAlerts:
@lxndrauthorSep 15.2010 — OK, here's a second update. It seems I can fix the problem but only be introducing another one. If I change the doctype from:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

to

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

the problem is fixed but in doing so a lot of other things on the site no longer appear right. I really don't understand why changing the doctype in this way should fix the problem but given that it does can anyone suggest another, more elegant way of fixing whatever the specific problem is ?
×

Success!

Help @lxndr spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...