14 replies [Last post]
Road
Offline
Regular
Last seen: 15 years 32 weeks ago
Joined: 2005-02-16
Posts: 17
Points: 0

Heya
I came along this interesting problem, and I cannot figure out what I'm doing wrong.
I hope that some of the CSS/Java gurus can spot the error and point it out to me and other,

This is a script that should in theory change the background pic of an <div> tag.

Page Sample: www.battlefield2.us

The Pic in Question is the little Fighter Aircraft pic at the right hand side, this should change from the current pic to the same pic just with some lines on top of it.

As you can see if you refresh the page nothing happens.

I copy and paste the importend code here:

Quote:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<head>
<title>Battlefield2.us Not another Fanboy page</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1" />
<meta name="Robots" content="NOINDEX" />
<meta http-equiv="PRAGMA" content="NO-CACHE" />

<style type="text/css">

body{
padding:0;
margin: 0;
background-color: #574E42;
}

#Top{
height:128px;
color:#333333;
margin:0;
padding:0;
background-image: url(banner_middle.jpg);

}
#banner {
position: absolute;
right:0px;
top: 0px;
width: 299px;
height: 128px;
background-image: url(banner_right.jpg);
}

#banner_left {
position: absolute;
height:128px;
width: 366px;
background-image: url(banner_left.jpg);
}


#copyright {
position: relative;
margin: 0 181px 20px 181px;
border: 1px solid #000000;
background: #B6A894;
color: #333333;
padding: 5px;
z-index: 3;
font-family: arial, verdana;
font-size: 12px;
text-align: center;
}
</style>

<script language="JavaScript">
<!--

function SymError()
{
return true;
}

window.onerror = SymError;

var SymRealWinOpen = window.open;

function SymWinOpen(url, name, attributes)
{
return (new Object());
}

window.open = SymWinOpen;

//-->
</script>

<script type="text/javascript">
<!--
if (document.getElementById) { window.onload = swap };

function swap() {
var numimages=2;
rndimg = new Array("banner_right.jpg", "banner_right_2.jpg";
x=(Math.floor(Math.random()*numimages));
randomimage=(rndimg[x]);
document.getElementById("banner").style.backgroundImage = "url("+ randomimage +")";
}
//-->
</script>

</head>
<body>

<div id="banner_left"></div>
<div id="banner"></div>
<div id="Top"></div>

I'm very interested how this could work and what I did wrong..

Many thanks in advance

Road
Offline
Regular
Last seen: 15 years 32 weeks ago
Joined: 2005-02-16
Posts: 17
Points: 0

Random banner Image (code in Thread included)

anybody

Road
Offline
Regular
Last seen: 15 years 32 weeks ago
Joined: 2005-02-16
Posts: 17
Points: 0

Random banner Image (code in Thread included)

wow 55 people check out the thread nobody answers or helps

thepineapplehead
thepineapplehead's picture
Offline
Guru
Last seen: 27 weeks 1 day ago
Joined: 2004-06-30
Posts: 9668
Points: 801

Random banner Image (code in Thread included)

Road, I see you are new here, so let me offer you a tip.

Don't bump your topics like this. There is a button at the bottom of CSS Creator marked 'view unanswered posts'. Bumping your topic removes it from this, so it cannot be found.

Back on topic, find out if your server supports PHP. If it does, there is a much easier technique for a random image.

Verschwindende wrote:
  • CSS doesn't make pies

Road
Offline
Regular
Last seen: 15 years 32 weeks ago
Joined: 2005-02-16
Posts: 17
Points: 0

Random banner Image (code in Thread included)

Thanks for pointing that out to me ... yes my server supports php ////

Tony
Tony's picture
Offline
Moderator
Brisbane
Last seen: 2 weeks 5 hours ago
Brisbane
Timezone: GMT+10
Joined: 2003-03-12
Posts: 5343
Points: 2964

Random banner Image (code in Thread included)

Hi Road,
Do you have the images in the same directory as the script page?

Road
Offline
Regular
Last seen: 15 years 32 weeks ago
Joined: 2005-02-16
Posts: 17
Points: 0

Random banner Image (code in Thread included)

yes I do, they are all in the root folder or better the folder where my index.php is

Tony
Tony's picture
Offline
Moderator
Brisbane
Last seen: 2 weeks 5 hours ago
Brisbane
Timezone: GMT+10
Joined: 2003-03-12
Posts: 5343
Points: 2964

Random banner Image (code in Thread included)

Hi Road,
the script looks fine, the problem seems to be the rest of the page.
You have many doctypes and css all through what should be the body.
There also appears to be a problem with mime types.
Heres the error that shows up in the JavaScript consol of Firefox when visiting the site.

Quote:
Error: The stylesheet http://fuzzy.phpwebhosting.com/404.html was not loaded because its MIME type, "text/html", is not "text/css".

Try to get the site to validate and your script should start working.

Hope that helps

Road
Offline
Regular
Last seen: 15 years 32 weeks ago
Joined: 2005-02-16
Posts: 17
Points: 0

Random banner Image (code in Thread included)

Hi
I just validated my page again and all seems fine.
Could you give me a hint how to fix that mime thingy ?

The only reason I have the css code on te index page is, because I wanted to test if that was the problem with the java code not working.

I guess i will take some time kout clean up the css and html code and see what happens than.

Any tips help are very welcome... thanks to all you guys for helping me so patiantly

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 5 years 37 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

Random banner Image (code in Thread included)

Road,
Please don't be upset but the problems Tony mentioned in his last post were all points that I went over in your other thread on problems with this page and in some detail.

You once again have said that the page validates, as you did on the other thread yet it can't possibly validate at the moment and indeed doesn't . Is there some confusion with what validation means ?

I mentioned the importance of fixing up the errors that the page was generating, yet you have started a new thread about new problems without seeming to correct these errors, to track down a problem it's essential that you eliminate any potential causes that present themselves in order to arrive at the root cause and these problems are themselves not ones that can be overlooked.

It's important to understand how someone may feel when help and advise is offered and yet doesn't seem to be acted upon it will tend to promote the attitude of why bother any further and you will tend to find that help will dry up somewhat which I'm sure you don't want We are willing and able to help but you do need to work with us on it.
If you don't understand points mentioned or need clarification on the issues we perceive then just say so, but it is vital for your own benefit to take note of them and be seen to be trying to deal with them.
Please do not be put of by what I've said as it is in all honesty intended to be helpful towards you.

Hugo.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

Road
Offline
Regular
Last seen: 15 years 32 weeks ago
Joined: 2005-02-16
Posts: 17
Points: 0

Random banner Image (code in Thread included)

I don't take it the wrong way... I honesly aprechiate all help from you and others.

If i go to this Page http://jigsaw.w3.org/css-validator/validator-uri.html

And Put in this address: http://fuzzy.phpwebhosting.com/~b4ne/page/index.php

I get the page validated..

CSS validated...

HTML is however a issue, I fix this today If i have time

I didn't open another thread because I want to avoid you I was under the impression that the page is fine and the java script should work, and is in any case a different problem all together.

I will not ask any more question before I have my page 100% working in both IE and Firefox Netscape.

Sorry to have bothered you

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 5 years 37 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

Random banner Image (code in Thread included)

I see you were validating the CSS styles, in some senses it's more important to validate the HTML first and indeed when "validate your page" is mentioned usually it refers to the HTML although that could be made clearer, so as not to confuse.

What Tony and I were attempting o point out is that fixing the errors mentioned may go some way to fixing the problems either way they need eliminating.

You don't have to wait until your page works 100% across browsers before asking anymore questions, anyway there would be none to ask then Smile clearing up the reported errors may still leave unresolved problems, but at least then we know that those page problems are not the cause and can focus on other areas.

Hugo.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

Road
Offline
Regular
Last seen: 15 years 32 weeks ago
Joined: 2005-02-16
Posts: 17
Points: 0

Random banner Image (code in Thread included)

I'm validating my HTMl atm but this is driving me nuts :

For excample:

#

Line 40, column 669: required attribute "ALT" not specified

...pimages/fullautoglock.jpg" border="0"></a> <br />(800K)</font></td>

The attribute given above is required for an element that you've used, but you have omitted it. For instance, in most HTML and XHTML document types the "type" attribute is required on the "script" element and the "alt" attribute is required for the "img" element.

Typical values for type are type="text/css" for <style> and type="text/javascript" for <script>.

✉
#

Line 49, column 4: end tag for "FONT" omitted, but its declaration does not permit this

</td>

..pimages/fullautoglock.jpg" border="0"></a> <br />(800K)</font></td>

What is this supposeted to mean ?
Am i supossted to delete the tag > ? in both instances ?

And I have like 100 of these marked as errors

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 5 years 37 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

Random banner Image (code in Thread included)

Road the validator is asking that you add the 'alt' alternative text attribute to your img tags.
If an image can't be displayed your meant to have the 'alt' attribute to display a text explanation in it's place i.e alt="this is a picture of....."

I'm not sure that this will help but I have run this page through the html-tidy plugin for FF to produce a cleaned up version of your page it has put in alt ="picture" for every img tag where it's found them missing and corrected what it's deemed to be other errors such as badly nested table elements etc.

It may be worth running this and seeing if it works 'Tidy' is not foolproof and it may have broken your layout in some respects but it may help.

If you don't have the plug in it's worth getting as it provides a quick error check on your offline pages as you go.

Hugo.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

Road
Offline
Regular
Last seen: 15 years 32 weeks ago
Joined: 2005-02-16
Posts: 17
Points: 0

Random banner Image (code in Thread included)

Thank you very much, that is some great help Smile