Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

syntax question - passing variable via function?

Status
Not open for further replies.

starblood

Technical User
Feb 28, 2001
63
GB
I have a line of script that works:

document.getElementById('layername').filters.alpha.opacity = 0;

What I would like to do is pass the variable via a function. Something like this:

function DoIt([COLOR=blue ]nameoflayer[/color]){
document.getElementById(nameoflayer).filters.alpha.opacity = 0
}

Onmouseover="DoIt('layername')"

BUT it doesn't like this, must be the syntax, any ideas?
 
Have you alerted your function parameter to make sure it's being received correctly?

i.e.,

Code:
function DoIt(nameoflayer){
[b]alert(nameoflayer);[/b]
document.getElementById(nameoflayer).filters.alpha.opacity = 0
}

That'd be the first thing I'd look at. Let us know!

--Dave
 
Thanks for the reply LookingForInfo. Done that - it returns 'layername' so the passing of the variable works. It is looking like I have my syntax wrong.

Here is a demo page to show the problem:


Any help would be greatly appreciated
 
Ah. Your problem seems to be that you only declare your WhichBrowser variable within if-blocks.

change:
Code:
if (document.all && document.getElementById) {[b]var[/b] WhichBrowser=1}
else if (!document.all && document.getElementById) {[b]var[/b] WhichBrowser=2}
else {[b]var[/b] WhichBrowser=3}
to:
Code:
[b]var WhichBrowser;[/b]
if (document.all && document.getElementById) {WhichBrowser=1}
else if (!document.all && document.getElementById) {WhichBrowser=2}
else {WhichBrowser=3}
...and I think that will do it for you.

Good luck!

--Dave
 
Got it. You're not sending parameters to FadeIn(...) on your setTimeout-call.

Try this line:

Code:
setTimeout('FadeIn([b]"'+nameoflayer+'", '+opac+'[/b])', 30);

'hope that does it.

--Dave
 
Cheers Dave - that's done it. Brilliant.

Feel a bit of an idiot for not spotting it myself - so obvious now I have been told. Woods and the trees I guess.

Thanks again - much appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top