/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Why can’t I run more than one function?

I’m having another small problem with a drop-down menu (one problem has been resolved).

I have a script on a page for a Google Map API.

Now, if I add a script to add a menu to the page, it doesn’t work. As far as I knew, all you had to do was to put a semicolon between functions called, but that doesn’t work, and I have no idea what else could be wrong.

[code]
<script type=”text/javascript”>

//google map script
function initialize() {
if (GBrowserIsCompatible()) {
var map2 = new GMap2(document.getElementById(“hfxmap”), { size: new GSize(470,300) });
var marker2 = new GMarker(new GLatLng(44.647284,-63.571959));
map2.addControl(new GLargeMapControl());
map2.addControl(new GMapTypeControl());
map2.setCenter(new GLatLng(44.647284,-63.571959 ), 16);
map2.addOverlay(marker2);
}
}

//menu script
//window.onload=function(){show(‘s’+document.body.id);};
//the above was originally where the menu’s onload function was, but with two functions now, I have no idea what to do.
function show(id) {
var d = document.getElementById(id);
for (var i = 1; i<=10; i++) {
if (document.getElementById(‘smenu’+i)) {document.getElementById(‘smenu’+i).style.display=’none’;}
}
if (d) {d.style.display=’block’;
}
}
[/code]

What can I do to call both functions to work properly?

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@TJ111Mar 31.2008 — <i>
</i>window.onload = function() {
show('s'+document.body.id);
initiliaze();
}

That doesn't work?
Copy linkTweet thisAlerts:
@LeeUMar 31.2008 — The first function called is overwritten by the second function called. Add the script below at the end of your script. Place the function calls at the bottom, where noted.

[CODE]
// Multiple onload function created by: Simon Willison
// http://simonwillison.net/2004/May/26/addLoadEvent/
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}

addLoadEvent(function() {
/* place a function here */
/* place another function here */
});[/CODE]
Copy linkTweet thisAlerts:
@dolph_lundgrenauthorMar 31.2008 — Okay. I swear I had that exact function and it didn't work.

I feel like an idiot.

Thanks TJ.
Copy linkTweet thisAlerts:
@TJ111Mar 31.2008 — Just for future reference, LeeU's function is a better alternative. Using his function you can add multiple onload event's anywhere in your code, mine you have to put every onload event inside that function.
Copy linkTweet thisAlerts:
@dolph_lundgrenauthorMar 31.2008 — Excellent.

Thanks guys.
Copy linkTweet thisAlerts:
@LeeUMar 31.2008 — Glad I could help.
×

Success!

Help @dolph_lundgren 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.18,
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,
)...