/    Sign up×
Community /Pin to ProfileBookmark

Making two javascripts coincide

I have two seperate JavaScripts that work fine alone but when they are used on the same page one of them doesnt work right. I don’t know much about JavaScript so I would love a little help in the matter.

The first one is a [URL=http://www.alistapart.com/articles/alternate/]css style switcher[/URL] so my users can try different site styles. The second one is a [URL=http://www.dynamicdrive.com/dynamicindex16/formremember.htm]form retain script[/URL] to remember username and web/mail for my shoutbox. When these two scripts are used at the same time the style switcher doesn’t work right. If you make a post on the shoutbox it somehow remembers what style you were using at the time of the post. Then you can still switch the style but if you go to a new page the style doesn’t remain. It will switch back to the style used to make the shout. If the style switcher script is working right it will remember which style you had selected on the previous page.

I looked over these two scripts and I can’t see why one is affecting the other. But when it comes to JavaScript i’m clueless and I am willing to bet its somthing simple to the trained eye. Here is also a link to the [URL=http://www.modernmorph.com/main.php]site[/URL]

[B]Note:[/B] I do have some other Javascripts inside of the switcher.js but those all worked fine together. The problem only occurs when cookie.js is added.

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@FangAug 13.2005 — The [I]onload[/I] & [I]onunload[/I] are causing the problem. Combine each call in it's own function:
window.onload = function(e) {
var cookie = readCookie("style"); //Alternate Style Sheets
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
setformobjects(); //Form Values script
}
do similar for onunload.
Copy linkTweet thisAlerts:
@ToeBeeauthorAug 13.2005 — I am a little confused about how to merge the two onloads and onunloads...
[CODE]window.onload = function(e) {
var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
setformobjects();
}

window.onunload = function(e) {
var title = getActiveStyleSheet();
createCookie("style", title, 365);
saveformvalues();
}[/CODE]

Somthing like that? I have a feeling I need to add more from the cookie.js onload and onunload? Also do I erase the onload and onunload from the cookie.js once the switcher.js is set up?
Copy linkTweet thisAlerts:
@FangAug 13.2005 — Delete all other function calls involving [I]onload[/I] & [I]onunload[/I].
Copy linkTweet thisAlerts:
@ToeBeeauthorAug 13.2005 — Ok Thanks Fang and sorry about that. I did just that last night. I could have swore it didn't work! But after reading your post I tried it again and it worked! lol I must have been tired.

Well thanks again Fang ?
×

Success!

Help @ToeBee 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.13,
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,
)...