/    Sign up×
Community /Pin to ProfileBookmark

Help with undefined error in script

I have the following code:

<script type=”text/javascript”>
<!–

var base = “images/”;
if (document.images) {
// DEFINE BUTTON PAIRS HERE… use buttonXon.gif and buttonXoff.gif
button1on = button1on.src = base + “button1on.jpg”;
button1off = button1off.src = base + “button1off.jpg”;
button2on = button2on.src = base + “button2on.jpg”;
button2off = button2off.src = base + “button2off.jpg”;
button3on = button3on.src = base + “button3on.jpg”;
button3off = button3off.src = base + “button3off.jpg”;
button4on = button4on.src = base + “button4on.jpg”;
button4off = button4off.src = base + “button4off.jpg”;
button5on = button5on.src = base + “button5on.jpg”;
button5off = button5off.src = base + “button5off.jpg”;
button6on = button6on.src = base + “button6on.jpg”;
button6off = button6off.src = base + “button6off.jpg”;
button7on = button7on.src = base + “button7on.jpg”;
button7off = button7off.src = base + “button7off.jpg”;
button8on = button8on.src = base + “button7on.jpg”;
button8off = button8off.src = base + “button8off.jpg”;
button9on = button9on.src = base + “button9on.jpg”;
button9off = button9off.src = base + “button9off.jpg”;
button10on = button10on.src = base + “button10on.jpg”;
button10off = button10off.src = base + “button10of.jpg”;
button11on = button11on.src = base + “button11on.jpg”;
button11off = button11off.src = base + “button11off.jpg”;
button12on = button12on.src = base + “button12on.jpg”;
button12off = button12off.src = base + “button12off.jpg”;
}
function imgOn(imgName) {
if (document.images) {
document[imgName].src = eval(imgName + “on.src”);
}
}
function imgOff(imgName) {
if (document.images) {
document[imgName].src = eval(imgName + “off.src”);
}
}
// –>

</script>

I get undefined errors on lines 41 and 46 the function imgOn and function imgOff. Here is one of the lines that call the function

<a href=”instru.html” onMouseOver=”imgOn(‘button12’)” onMouseOut=”imgOff(‘button12’)”><img border=”0″ name=”button12″ src=”images/button12off.jpg” alt=”Instruments”></a>

Can you help me with the undefined errors.

Thanks

mbeasle

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@Khalid_AliJun 15.2004 — undefined error is caused when you try to use a JavaScript object/variable with out defining/initializing it.

Make sure you go thru the objects and see which one is not being initialised(41,46) and then see why not.
×

Success!

Help @mbeasle 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.19,
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,
)...