Click to See Complete Forum and Search --> : conflicting scripts?


khaki
03-05-2003, 11:34 AM
Hi guys ! ...

I hate to do this... but I'm gonna do this:

I have 2 seperate cross-browser scripts.

#1 is a Javascript Dropdown Menu that I lifted (and have used a lot) from JavascriptSource.com.
I understand it enough to modify it for my needs, but I can not, do not, and will not make claims to understanding the bulk of it.
It works fine though (and aside from being a Javascript dependent menu), I love it (it's my baby. Adopted, of course. lol).

#2 is a Javascript Slide Show that I lifted (note the pattern forming here. lol) from DynamicDrive.com.
I am able to modify it and it works fine (just please don't hold me accountable for the images that it's displaying. I think everyone knows that I have a bit more of an edge than that. wink).

The problem is.....
When both are used together on the same page... the Menu does not work (appear) in IE only (can you believe that?! It works great in Netscape of all things, but not IE!!!! unfknblvbl).

Now... I have (really) gone through both of these scripts searching for conflicting variable names or whatever... but I can't find anything (and the sad truth is... I don't even know what the heck I'm looking for really).
And unfortunately I can only do basic Javascripts myself (nothing of the scale of these 2 scripts, that's for sure).

So I was wondering if one of you resident geniuses could help me to understand the problem here.
(aside from my propensity for lifting other people's scripts and expecting them to work when they break, that is. I'm fully aware of my crimes, so please don't lecture me. I am trying to learn as i go. Really!).

Well here is the page.
I made all of the links absolute, so this will work as is (although I will provide the JS files as well, if requested. I'm not looking to make this any harder for anyone who is willing to help me with this - so please just let me know). Also, everything is default... I did not modify anything in any of the code (except the absolute references):

PLEASE PLEASE PLEASE PLEASE PLEASE help me understand why these scripts won't work together in IE.
T h a n k y o u !

2 "tired" eyes and a very unconvincing smile right now..
k

----------------------------------------------------------------------------------

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<meta name="Content-Script-Type" content="text/javascript">
<TITLE></TITLE>
</HEAD>
<BODY>

<script type='text/javascript' src='http://javascript.internet.com/navigation/nwrmenu_var.js'></script>
<script type='text/javascript' src='http://javascript.internet.com/navigation/menu_com.js'></script>

<script language="javascript">

var slideshow_width=140
var slideshow_height=225
var pause=3000

var fadeimages=new Array()
fadeimages[0]="http://www.dynamicdrive.com/dynamicindex14/photo1.jpg"
fadeimages[1]="http://www.dynamicdrive.com/dynamicindex14/photo2.jpg"
fadeimages[2]="http://www.dynamicdrive.com/dynamicindex14/photo3.jpg"

var preloadedimages=new Array()
for (p=0;p<fadeimages.length;p++){
preloadedimages[p]=new Image()
preloadedimages[p].src=fadeimages[p]
}

var ie4=document.all&&navigator.userAgent.indexOf("Opera")==-1
var dom=document.getElementById&&navigator.userAgent.indexOf("Opera")==-1

if (ie4||dom)
document.write('<div style="position:relative;width:'+slideshow_width+';height:'+slideshow_height+';overflow:hidden"><div id="canvas0" style="position:absolute;width:'+slideshow_width+';height:'+slideshow_height+';top:0;left:0;filter:alpha(op acity=10);-moz-opacity:10"></div><div id="canvas1" style="position:absolute;width:'+slideshow_width+';height:'+slideshow_height+';top:0;left:0;filter:alpha(op acity=10);-moz-opacity:10"></div></div>')
else
document.write('<img name="defaultslide" src="'+fadeimages[0]+'">')

var curpos=10
var degree=10
var curcanvas="canvas0"
var curimageindex=0
var nextimageindex=1


function fadepic(){
if (curpos<100){
curpos+=10
if (tempobj.filters)
tempobj.filters.alpha.opacity=curpos
else if (tempobj.style.MozOpacity)
tempobj.style.MozOpacity=curpos/100
}
else{
clearInterval(dropslide)
nextcanvas=(curcanvas=="canvas0")? "canvas0" : "canvas1"
tempobj=ie4? eval("document.all."+nextcanvas) : document.getElementById(nextcanvas)
tempobj.innerHTML='<img src="'+fadeimages[nextimageindex]+'">'
nextimageindex=(nextimageindex<fadeimages.length-1)? nextimageindex+1 : 0
setTimeout("rotateimage()",pause)
}
}

function rotateimage(){
if (ie4||dom){
resetit(curcanvas)
var crossobj=tempobj=ie4? eval("document.all."+curcanvas) : document.getElementById(curcanvas)
crossobj.style.zIndex++
var temp='setInterval("fadepic()",50)'
dropslide=eval(temp)
curcanvas=(curcanvas=="canvas0")? "canvas1" : "canvas0"
}
else
document.images.defaultslide.src=fadeimages[curimageindex]
curimageindex=(curimageindex<fadeimages.length-1)? curimageindex+1 : 0
}

function resetit(what){
curpos=10
var crossobj=ie4? eval("document.all."+what) : document.getElementById(what)
if (crossobj.filters)
crossobj.filters.alpha.opacity=curpos
else if (crossobj.style.MozOpacity)
crossobj.style.MozOpacity=curpos/100
}

function startit(){
var crossobj=ie4? eval("document.all."+curcanvas) : document.getElementById(curcanvas)
crossobj.innerHTML='<img src="'+fadeimages[curimageindex]+'">'
rotateimage()
}

if (ie4||dom)
window.onload=startit
else
setInterval("rotateimage()",pause)
</script>

</BODY>
</HTML>

Jona
03-05-2003, 01:05 PM
Chances are both scripts are using the same function(s)/object(s) at the same time, and therefore only one of the functions get it. So one of them isn't working because of that. Look in your .js files and make sure none of the functions have the same names as anything in your page. Make sure none of the variables have the same names either.

pyro
03-05-2003, 01:07 PM
Hey, khaki...Here's the solution....

Way down by the bottom of the script you have these lines:

if (ie4||dom)
window.onload=startit
else
setInterval("rotateimage()",pause)


Remove those and add an onload to you <body> tag like this:

<body onLoad="startit();">

Jona
03-05-2003, 01:10 PM
Hey, khaki...Here's the solution....

Way down by the bottom of the script you have these lines:

if (ie4||dom)
window.onload=startit
else
setInterval("rotateimage()",pause)


Remove those and add an onload to you <body> tag like this:

<body onLoad="startit();">


Oh yah, man I hate this... I forgot to check for that part. Sheesh! I'm so dumb... :p

pyro
03-05-2003, 01:12 PM
Jona, I edited my post to show an even better way to do it...

Jona
03-05-2003, 01:26 PM
So did I.... LOL

khaki
03-05-2003, 01:28 PM
PYRO!!!!!
MY HERO!!!!
YOU ALWAYS COME TO MY RESCUE!!!!

That's it! (you knew that, of course).

See.....?
I should have seen that, but I'm such a Microsoft girl that a call to another function (or sub) does not require the parenthises when not passing arguments (as is required in Javascript). So I didn't pick that up. UGH!
See...? I don't even know what I'm looking for even when I can see it. sigh

Syntax, variables, operators.....
I just can't think with a Javascript brain. I suck at Javascript! CR*P!

But thank you so much Pyro.

whisk me away to the Pyro-cave sweety... I'm all yours (wink)...
k

khaki
03-05-2003, 01:41 PM
oh... you keep posting...


ok, i did that (and it still works in both browers with that additional change).

but... why is that better (other than less lines)?
I don't understand why it would still work in Netscape without the if/then/else call to :
setInterval("rotateimage()",pause)

I'll continue to look at it, but I am just so glad it works.
Thanks again (you too Jona!).

definitely smiling...
k

khaki
03-05-2003, 01:49 PM
ok... never mind.
I see it.

startit() also calls setInterval("rotateimage()",pause) .

Was that just originally badly written then, or was there a reason for the way that was done?

I really should break that script down and try to understand all of it's parts (one of these days. lol).

Oh well, sorry for the back-to-back-to-back posts (not the first time i've done that... probably not the last either).

I'm so glad I asked this question. I almost didn't. But I actually learned something from it beyond just having it solved for me.
Thanks.

high-fives all around...
k

Jona
03-05-2003, 01:55 PM
Hey, you know the basic idea here is that when you get a script from Dynamicdrive.com or from Javascriptsource.com, they always give you the script for it to run exclusively: on its own. Which means you always have to look at the bottom of the script, and change it to make it where the page is compatible to run two functions. Which is why you'd take off the window.onload=functionName(); and change it to <body onload="functionName();">. So that's the basic point.... :)

Oh, BTW, I'm not sure, but I believe that the reason you're not, "good at Javascript" is because perhaps you don't look at the code enough? I dunno, it's just my opinion I guess. You see, I used to never understand a bit of Javascript, but I spent about 2 hours a day looking at this stuff, and after about 2 months of that, everything started making sense. You just have to get used to the syntax used mainly. Just like me, I can program in Visual Basic (easily, the language is totally simple) but a lot of times I go back to my Javascript thinking. It's just because I'm soooo used to working with Javascript (and like syntax). ...Hope you caught all that... *Looks at Pyro, uh oh, hey, Pyro, you wanna help me out? Uh, she's looking at me kinda' weird.... LOL.. Just kidding...*

khaki
03-05-2003, 02:36 PM
Hey Pyro... Jona is making fun of me and calling me lazy.
LOL. Just kidding (a little :mad: . wink)

But seriously, I do work with Javascript... and i normally survive ok.
I don't know why i have mental blocks on the syntax sometimes. I mean, I know that javascript has different syntax when i actually sit down and write it (and after about 30 minutes of unsuccessful attempts until I realize that I need to add another = sign to make a comparitive statement work (what's up with that... I hate that! I know it... but it gets me every stupid time! grrrr)

But anyway... I fight Javascript and that's probably part of the problem. But at the same time, I don't always have 2 hours a day to look at stuff that works. I need to keep producing stuff or I'll be selling pencils from a cup.

I've got plenty to keep track of, Jona. ASP, CSS, SQL, VBscript, VBA (so much Excel programming it makes my head spin), etc. So please... I know you mean well... but I already spend time on Javascript and sometimes it is not very productive time for me (that's why I love this forum and you guys. wink!).

I envy you guys (and GIRLS!) who take to this stuff so naturally. But for me (and a lot of others, i suppose), it's a bit of a struggle. It's not from lacking of trying though, so please... don't question my dedication towards learning the language (that wouldn't be fair).

I want to thank you for the tip on handling the onLoad function though. It makes so much sense that it's embarrassing to not intuitively think of doing it automatically. Sometimes it's probably wise to just slow down and keep the logic simple. That's a lesson which escapes me more often than not, i'm afraid.

Ok... sorry for the long post (agian).
I guess I can't help that either. And as Dave Clark once commented:
"Dat girl do like to carry on".

slipping away for the rest of the day...
k

Jona
03-05-2003, 02:45 PM
I never called you lazy! I wansn't making fun of you either!

I was just suggesting to you what I did to learn Javascript. That's all. I was merely trying to help you out. I don't know whether or not you need Javascript, and if so to what extent, but I do know that if I can or could ever help anyone I'd sure enough do it! Please try to understand, if you've got it made with VB, ASP, etc., then that's fine with me. My main reason for being here is to answer other people's questions, not to ask them (although, I occasionally do).

We all post long messages. One of the main things that discerns programmers from other people, is the fact that they always use long messages and usually use proper punctuation (at least).

My appologies, nevertheless, I am sorry for whatever you thought I did. :p (See? I typed a long message, too!)

pyro
03-05-2003, 02:49 PM
Originally posted by Jona
*Looks at Pyro, uh oh, hey, Pyro, you wanna help me out? Uh, she's looking at me kinda' weird.... LOL.. Just kidding...* ...lol. :D

Anyway, for me, javasript really started to make sense when I really started using it. Prior to that, I'd just play around with it a bit, and never really understood thinks like loops, arrays, etc. Once you wrap your head around that, it becomes so much simpler. It is also quite nice that once you learn one language, (like javascript) you are able to simply pick up others. (PHP, CGI/Perl, Even C all have similar syntaxes -- ASP on the other hand...;))

I am also here to help people out. I've often wondered why so many people (myself included) would spend so much time giving free advise. For me, the answer is simple.... I have become so much better of a programmer as a result of spending endless hours working on problems. And the knowledge that I obtain through helping others makes it all worth it.

Anyway...Those are some of _my_ thoughts on the issue...

Jona
03-05-2003, 02:56 PM
It is also quite nice that once you learn one language, (like javascript) you are able to simply pick up others. (PHP, CGI/Perl, Even C all have similar syntaxes -- ASP on the other hand...)

Yah, I know what you mean... ;) Ugh, ASP...... Microsoft put their foot into the Web! Oh no! LOL! J/k!

Basically, you're totally right, Pyro. Let's review: helping people mainly because it helps you to become a better programmer. Yes, but I also do it because it's just so much fun to help people out!

LOL, you know, once there was this guy asking a question about window.open(), and I was interested in who had hired him, just because I was interested. Well, hehe, I asked after I answered his question, "Oh and by the way, who hired you?" I guess he took it the wrong way... I haven't seen him reply or post a message since....

Anyway, back to the topic... LOL :p

pyro
03-05-2003, 03:04 PM
lol...That's funny, Jona...

Yup, you pretty much summed up why I am here in your second paragraph. Isn't it great to be able to show people with less experience how to do new things... (Or, normally, do it for them...hehe)

khaki
03-05-2003, 03:13 PM
hey!

I was gonna leave you guys alone to enjoy your little moment together, but now your both taking swipes at me.

just kidding.

hey Jona... i know what you were saying... but it tweaked me because i was originally not even going to ask this question.
Then your comment made me feel stupid for doing so (but that was just because it played into my insecurity about not knowing how to do something).

I know you help. sorry for over-reacting.

Well i better bolt out of here before this gets too long too.
k

pyro
03-05-2003, 03:17 PM
Originally posted by khaki
Then your comment made me feel stupid for doing so (but that was just because it played into my insecurity about not knowing how to do something).I know how that is. I think we all have trouble admitting that we need help...I sure do... :(

khaki
03-05-2003, 04:24 PM
...and once again coming to my rescue.

how sweet!
k

Jona
03-05-2003, 08:39 PM
Yah, I love it. :p Especially the, "doing it for them" part... you see, I'm always so bored because I can't think of a new something to do with JavaScript. I've got this folder on my (other) computer, called "Experiments." Well, they're not exactly experiments, but it's a cool name. Anyways, that folder is filled with scripts such as my "names" script, my "next_mid" script, my *famous* "dynamicusrpage" script, and many others that I make including cookie scripts and parsing the URL scripts (you know, "page.html?formItem=someValue&printSomethingtoThePage=some%20words").

Jona
03-05-2003, 08:42 PM
Okay now..

I guess you're just not getting it. I know I may sound harsh, I try not to be. I love helping people, and I never meant anything bad by what I said. Making you feel stupid is called humility, and it is how we learn. Learning from your mistakes is one of the best ways to learn. Take it from me: I've done it countless times in Javascript myself.... ;)

khaki
03-06-2003, 08:39 AM
ok ok
relax jona

i have already sincerely apologized for over-reacting to your statements to me.

the rest was all in fun.
there's really no need to analyse me further. please.

sheesh. doesn't your profile description say "programming = fun"?
please try to recognize when i'm playing and when i'm being serious.
i was playing.

not using "proper punctuation" (wink)...
k

khalidali63
03-06-2003, 08:43 AM
lol..You should play a bit harder(wink),cus jona did not feel that you were..

:p

Cheers

Khalid

khaki
03-06-2003, 09:09 AM
khalid wrote:
You should play a bit harder(wink)
khalid... if i played any harder on these boards, i would be bannished for my irrelevance (lol).

jona just hasn't figured me out yet (and i admit that i don't always make it easy. Just look at
how you and i have butted-heads in some past posts... and yet i adore you. you know that... right?).

it's really quite easy:
i'm almost always having fun... and when i'm not, i usually make it pretty clear and obvious
that i am distressed.

(i wish there were some others on these boards who could be as simple to understand!!!)

causing much head-shaking and eye-rolling with every word i type...
k

Jona
03-06-2003, 04:49 PM
Khaki, look I'm really sorry. I couldn't tell when you were serious and when you were joking. I knew you had appologized (which was really my part, since you were the one "offended"). My profile does say, "programming = fun" but I've always had a problem understanding people which is something I really try hard at. Being a Webmaster, I have to understand what my clients want, and I'm not always talking to them face-to-face. It's fun to joke around, and it's fun to make jokes, and I simply adore humor; however I do realize that there is a time to be serious and a time for apologies. My apology to you was sincere; yours to me--I wasn't, at the time, completely sure. Sorry for any misconceptions we have had together. Well, I better go run off and work on something...... adios....................................... oh, P.S. I leave on a good note ;)