If that other script were actually setting the value, declaring it as a VAR creates a new variable with the same name local in scope to that new function, so it cannot be passed. If 'saskia' is defined outside your DOMcontentLoaded function, DO NOT DECLARE IT INSIDE if you want to access it.
Though there are a host of other issues.
1) Really there's no reason to call DOMContentLoaded -- ever. If you want that behavior it's far easier to just make sure all your scripts that need that behavior are simply right before </body> in the markup. To avoid namespace conflicts, I'd then use an anonymous function.
2) If you are going to declare multiple variables in a row, you don't need to say 'var' every single time, you can make them a comma delimited list instead.
3) get a doctype on it. JS can actually behave differently (even in modern browsers) without one.
4) I probably wouldn't be wasting a SWITCH/CASE on this. I'd have the images in an array, and then do a IF to check if that variable is set, and within range of the array's length.
5) Don't use the style attribute... and really, PX metric fonts? Uhg.
6) @JMERKER, IMG is a inline level tag, it can't be a direct descendent of BODY. Likewise it is usually a better idea to only call document.getElementById once and store it, since that function is SLOW...
This WOULD do what Sasserl is asking:
Except for one problem...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<p>Inhaber Klaus Raser</p>
<h2>Ihr Partner für Auto- und Motorradzubehör</h2>
In Kooperation mit: <a href="Startseite.html">Tempolimit GmbH, HH</a>
This DIV is lip service to HTML, an IMG tag is a inline element and cannot
be a direct descendent of BODY. You MUST put at least one block level
container around it!
<img id="mainImg" src="moto1.jpg" alt="moto1.jpg" />
baseURL = 'http://test.nugg.ad/customers/Saskia/HTML/',
images = [
mainImg = document.getElementById('mainImg');
if (!saskia || isNaN(saskia) || saskia > images.length) saskia = 0;
mainImg.src = baseURL + imgSource;
mainImg.alt = imgSource; // not that the filename is useful alt text :(
You can't have a space between data and pixels. The other script is throwing an error there, so the later variable "saskia" is never even getting set!
var data pixels='9';
Hope this helps.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)