HighDots Forums  

Re: Javascript, works good in IE but in Firefox Mozilla it givesproblems

Cascading Style Sheets Layout/presentation on the WWW (comp.infosystems.www.authoring.stylesheets)


Discuss Re: Javascript, works good in IE but in Firefox Mozilla it givesproblems in the Cascading Style Sheets forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
RobG
 
Posts: n/a

Default Re: Javascript, works good in IE but in Firefox Mozilla it givesproblems - 04-03-2006 , 08:00 PM






shafiqrao (AT) gmail (DOT) com said on 04/04/2006 7:07 AM AEST:
Quote:
Hello everyone,

I have a script that runs in IE great, but in firefox it has problems.
I understand that there are some objects that are accessed differently
in IE and Mozilla. Can anybody let me know what I need to change in the
file to make a copy that would run fine on Firefox?

Here is the link to the file:
http://people.emich.edu/srehman2/study/polls.html click on the 'Build
Bars' link displayed at the top-right corner. I am copying the source
code here also,

================================================== =======
script language="javascript"
The language attribute is deprecated, type is required:

<script type="text/javascript">


Quote:
function BuildResults()
{
var str;
var imageWidths = new Array();
When posting code, use spaces for indentation rather than tabs, with 2
or 4 spaces per level.

You can initialise an array with:

var imageWidths = [];


Quote:
var imageName = new Array();
var labelName = new Array();
var imageSize = 140;
var BarImage = "images/poll_yellow.gif";
var t = new Array();
var color = new Array();
t[0] = 60;
t[1] = 30;
t[2] = 50;
t[3] = 112;
You can initialise this array as:

var t = [60, 30, 50, 112];

Quote:
color[0] = 'red';
color[1] = 'blue';
color[2] = 'silver';
color[3] = 'green';
And this one:

var color['red', 'blue', 'silver', 'green'];


Quote:
str = str + '<table cellspacing=2 cellpadding=0 border=0><tr><td>';
for(var i=0;i<t.length;i++)
{
imageWidths[i] = Math.round(imageSize * (Math.round(t[i])/100));
imageName[i] = "imageResult" + i;
labelName[i] = "spanPercentage" + i;
str = str + '<table cellspacing=2 cellpadding=0 border=0 height=4>';
str = str + '<tr><td bgcolor=' + color[i] + '><img name=' +
imageName[i] + ' id=' + imageName[i] + 'src="images/pixel.gif" width=1
----------------------^^-----------------^^^

You have not quoted the value of the id attribute and there is no
whitespace bewteen the end of the value and the start of the name of the
src attribute, so the HTML looks like:

... id='imageResult0src="images/pixel.gif"' ...

It is always a good idea to quote attributes even when not strictly
necessary. Inserting a space before the src attribute fixes the problem
for now...

If you use a strict doctype, Firefox will show the changing percentages
but not the growing bars. Trip it into quirksmode (remove any reference
to doctype) and you'll see the same results as IE.

Investigate these issues in a CSS forum:

news:comp.infosystems.www.authoring.stylesheets

Incidentally, a much more efficient result could be achieved by using
divs for the bars and simply modifying their style attributes, there is
absolutely no need to generate a mass of nested tables every single time.


Quote:
height=1 border=0></td><td><span id=' + labelName[i] + '>' +
Math.round(t[i]) + '%</span></td></tr>';
Don't allow posted code to auto-wrap, manually wrap it at about 70
characters to allow for a few replies.


[...]
Quote:
setTimeout("Wait()", 10);
[...]

Quote:
function Wait()
{
//Wait for a second
}
How do you intend to do that?


[...]


--
Rob
Group FAQ: <URL:http://www.jibbering.com/FAQ>


Reply With Quote
  #2  
Old   
shafiqrao@gmail.com
 
Posts: n/a

Default Re: Javascript, works good in IE but in Firefox Mozilla it gives problems - 04-04-2006 , 10:02 AM






Awesome Rob, you have solved my problem.

I am not a javascript programmer, but I knew some javascript some years
back ... thats why you might see my code is old fashioned and slow may
be.

I would think into changing the code to implement divs and changing its
style properties (I guess you mean width by that)

for function Wait(), this function is doing nothing i guess, I will
remove it also when I will be purifying my code for efficiency.

Once again, thanks for the help .. I really appriciate your detailed
and informative reply!

-Shafiq.


Reply With Quote
  #3  
Old   
Dr John Stockton
 
Posts: n/a

Default Re: Javascript, works good in IE but in Firefox Mozilla it gives problems - 04-06-2006 , 09:26 AM



JRS: In article <hYFYf.962$Nv4.135035 (AT) news (DOT) optus.net.au>, dated Wed, 5
Apr 2006 02:29:33 remote, seen in news:comp.infosystems.www.authoring.st
ylesheets, RobG <rgqld (AT) iinet (DOT) net.au> posted :
Quote:
--
Rob
Group FAQ: <URL:http://www.jibbering.com/FAQ
That could be misleading here ...

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.