Javascript issue

software development

#1

I noticed that my small script does not work in firefox, but does in IE 7. Would anyone have any suggestions.
The pages have been transformed into xhtml just so you are aware.

Here’s the code:

function disappear(obj) {
if (obj.style.display == “”) {
obj.style.display = “none”;
}
else {
obj.style.display = “”;
}
}

Here is partial text thats just before the hidden links…

Forums

Click here to display or hide the Forums...

BTW, On the error page, it is stating that lightwaveforum is not defined.
Silk

My website


#2

I suggest you stop being lazy and define your variables before you attempt to use them and stop assuming that somebody else will do it for you.

Firefox supports the W3C DOM. Having said that here is some light reading:
Document Object Model (HTML) Level 1 - Objects related to HTML documents

:cool: openvein.org -//- One-time [color=#6600CC]$50.00 discount[/color] on [color=#0000CC]DreamHost[/color] plans: Use ATROPOS7


#3

(RANT)

  1. I am not lazy
  2. I did not know they needed to be defined in any way.
  3. I did not expect anybody to do it for me
  4. I only ask what was the problem
  5. Thanks for being so rude and obnoxious.
    Why do you assume I want anybody to do anything for me, I have gone out of my way to help others on this forum. I rarely if ever ask for help. I do not think what you said was called for at all.
    (rant off)

My skills in javascript are still at beginner stage I was assuming it should work because it worked in IE. I forget where I found this script, but it was explained that the varible gets passed from the eventhandler to the script and becomes the element.
So now I need to figure out whether the varible name in the eventhandle needs to be defined or the varible obj in the script.
Thanks anyway,
Silk

My website


#4

Firefox sometimes seems to have issues with handling of objects while IE is more forgiving. I prefer to pass an id and then use getElementById();

Watch out for scrolling :wink:

[code]function toggleDiv(selectedDiv) {
if (document.getElementById(selectedDiv).style.display == ‘’) {
document.getElementById(selectedDiv).style.display = ‘none’;
} else {
document.getElementById(selectedDiv).style.display = ‘’;
}
}

Lead Process (+/-)

Blahblahblah...

[/code]

#5

[quote]My skills in javascript are still at beginner stage I was assuming it should work because it worked in IE. I forget where I found this script, but it was explained that the varible gets passed from the eventhandler to the script and becomes the element.
So now I need to figure out whether the varible name in the eventhandle needs to be defined or the varible obj in the script.
Thanks anyway,
Silk
[/quote]
I was being SARCASTIC. What you don’t know is that Internet Explorer will automatically pollute the JavaScript namespace with references to element objects with IDs. There is no standard that says it has to do that. It is another Microsoft “feature” they come up that allows JavaScript coders to use less code - hence the laziness.

And it is a basic idea of computer programming that a variable needs to be declared and assigned a value in order to “use” it. If you notice the source you posted does not do that at all.

The proper way to get an object reference to an HTML element of a document given an ID is to use a method of the document object called getElementById()

So to revise your code…

[code]function disappear(obj) {
// quit if obj was not defined to avoid error messages
if (obj === undefined) return;
// following code assumes obj is an element
if (obj.style.display == “”) {
obj.style.display = “none”;
}
else {
obj.style.display = “”;
}
}

Click here to display or hide the Forums...

[/code]

:cool: openvein.org -//- One-time [color=#6600CC]$50.00 discount[/color] on [color=#0000CC]DreamHost[/color] plans: Use ATROPOS7


#6

Thanks to both of you. Sorry for my rant earlier I guess you just hit just right. I was reading a little on the getelementbyid, but it wasn’t clicking.
Anyways, I’ll try this tomorrow it getting a little late.
Again thanks,
Silk

My website


#7

Works great in both IE and Firefox. Once again thank you.

This is the page I was working on…Still have a formatting issue, but thats another day…
links
Silk

My website