/    Sign up×
Community /Pin to ProfileBookmark

I am in an entry level web dev class and have made this javascript program – The images will not show, not to mention change. Can someone, please help me narrow in on my program error.

<html>
<head>
<title>Clinic8</title>
<!– Renee Gilbert,04/26/03, Assisgnment 8-1—>
<!–Generate random image file –>
<script language=”JavaScript”>
<!–Hide from non-JavaScript browsers
function ImageName(number)
{
var Image = new Array();
Image[0] =”image1.jpg”;
Image[1] =”image2.jpg”;
Image[2] =”image3.jpg”;
return ImageName [number];
}
//Stop hiding –>
</script>
</head>

<body bgcolor=”silver” text=”navy”>
<h1 align=”center”><font color=”darkblue” face=”monospace”>My Home Page</font></h1>
<hr align=”center” size=”2″ width = “100%” color=”navy” noshade>

<h2>Welcome to my Web site!</h2>
<p>

<script language=”JavaScript”>
<!–Hide from non-JavaScript browsers
var ImageName=Image;
number = Math.round()*2;
var name = ImageName();
document.write(‘<img scr=() “+name+” width=200 height=200 align=”left”>’);
//Stop hiding –>
</script>

</p>

<p> To display different images on my Home web page I used JavaScript language.
You can use all of the JavaScript expressions and operators to create your
own customized functions. A function is a series of commands that performs
an action or calculates a value. A function consists of the function name,
which identifies it; parameters, which are values used by the function; and
a set of commands that are run when the function is used. Function names are
case-sensitive. The function name must begin with a letter or underscore (_)
and cannot contain any spaces. A command block is a group
of commands within a function that is delimited by curly braces. There is
no limit to the number of function parameters that a function may contain.
The parameters must be placed within parentheses, following the function name
and the parameters must be separated by commas.
</p>

</body>
</html>

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@beebobMay 01.2003 — you initialize a new image object normally like that

[code=php]
var img = new Image();
img.src = "yourimage.jpg";
...
[/code]


you maybe want to do this?

[code=php]
<script>
function myImage(number)
{
var Image = new Array();
Image[0] = new Image();
Image[0].src ="image1.jpg";
Image[1] = new Image();
Image[1].src ="image2.jpg";
Image[2] = new Image();
Image[2].src ="image3.jpg";

return Image[number];
}

img1 = myImage(0);
img2 = myImage(1);
img3 = myImage(2);

document.writeln('<img scr= "+img1.src+" width=200 height=200 align="left">');

document.writeln('<img scr= "+img2.src+" width=200 height=200 align="left">');

document.writeln('<img scr= "+img3.src+" width=200 height=200 align="left">');
</script>
[/code]


beebob
Copy linkTweet thisAlerts:
@NedalsMay 01.2003 — Looking at the code you posted, I'm not sure what you want to do.

When changing images within a document, after the document has loaded, there are two seperate things you need to do.

  • 1. Preload your images using (posted by beebob)

    var img = new Image(); img.src = "yourimage.jpg";

    (not in a function OR in a function activated onLoad)


  • 2. Create your image change function.

    function chgImage(img) {

    document.imagename.src = img; // img = "yourimage.jpg"

    }


  • Hope that helps!
    Copy linkTweet thisAlerts:
    @beebobMay 01.2003 — yeah, I even was wondering a bit.

    maybe there were problems while pasting?
    ×

    Success!

    Help @hutchstarsky 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 5.7,
    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: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

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

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...