Javascript undefined variable Firefox

Soldato
Joined
6 Aug 2007
Posts
2,516
Hi,

I'm working with SharePoint.

I have some Javascript that i am using to show or hide fields depending on what tab the user is viewing.

As of now the code works fine in IE7 / 8. But does not work in Firefox / Opera.

The error i am recieving is: "TypeError: control is undefined".

http://pastebin.com/FDLEbygD

Anyone have any ideas?
 
It sounds like the 'findacontrol' method is returning null. You could step into that method using firebug to see what is failing.

Bit of a long shot as I can't remember off the top of my head, but is there a difference between the way the browsers treat case-sensitiveness in JavaScript? 'findacontrol' seems strangely named, should really be findAControl.
 
I can't help with your specific problem, but my advice would be to throw that away and write it from scratch. The code is appalling - so much needless repetition.

Also, how come jQuery is being included but you're using native javascript? jQuery would make that whole script about 10 lines long. It would also deal with the issue of having to use different methods to get access to the DOM in different browsers - which is seemingly the cause of your problem.
 
Bit of a long shot as I can't remember off the top of my head, but is there a difference between the way the browsers treat case-sensitiveness in JavaScript? 'findacontrol' seems strangely named, should really be findAControl.

It shouldn't make a difference as "findacontrol" is a function, as long as all the callings match it should be working as intended.

I can't help with your specific problem, but my advice would be to throw that away and write it from scratch. The code is appalling - so much needless repetition.

Also, how come jQuery is being included but you're using native javascript? jQuery would make that whole script about 10 lines long. It would also deal with the issue of having to use different methods to get access to the DOM in different browsers - which is seemingly the cause of your problem.

You are right, it is appalling, but as far as i know this is the best way to approach this when using SharePoint. We are very restricted in how we can hide the fields.

jQuery is included by accident, I didn't remove it after finding out that SharePoint + jQuery don't get on well at all.

Thanks.
 
Last edited:
After a bit of experimenting it's due to your ! tags.

IE 7 and 8 recognise them but IE 9 and firefox don't.

http://pastebin.com/p9tbXX2W

Lob that in a file and test it out.

That does indeed seem to be the case.

I've tried alternatives such as "*" and even blank. None work the same, does anyone know an alternative to getElementsByTagName("!") that will simply grab all the tags, whilst still being compatable across multiple Browsers?

Thanks.
 
Could you not amend your HTML to put a class on each element you need to check in Javascript? It'd be far quicker in the browser, and easier to write.
 
You should be able to replae the ! With anything else, "myTagOrSomething".

I've not really used js much though.

Also you should rewrite it as there is lots of repetition as spunkey said.
 
Hey guys,

Just a quick update.. i scrapped the Javascript and managed to get jQuery working.

The only problem is when I'm using jQuery IE is extremely slow when clicking tabs.. Firefox, Safari, Opera, Chrome all load them instantly.

This is a problem as most of the users will be using IE.

Anyone have any ideas on how to speed this up a little?

http://pastebin.com/E1u16Y4D

Thanks in advance.
 
It's slow due to having to use the :contains selector, followed by closest. JS performance in IE is far below what could be considered good, and that is a very inefficient selector, followed by an ok one.

Is there no way you could put a class on each of your inputs? That would speed it up instantly.

Could you post a sample of the HTML you have? There may be another way of achieving what you need.
 
Back
Top Bottom