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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function works in IE & Opera but NOT Firefox?!

Status
Not open for further replies.

daveh

Technical User
Jun 22, 2000
57
GB
Hi there,

I have a function (one of many) which is called onclick of a number of different elements of a form. This function works perfectly (with no detected script errors) in Internet Explorer, and I have even downloaded Opera to check it, where it works fine too. However, Firefox will not only run the function, but when this function is within the code of the page, NONE of the JavaScript on that page works, regardless of whether the function is being called or references.

Code:
// Function to show/hide countries within each IMT based on which IMT(s) is/are selected
function checkIMT(imt, int) {
	neiotleadimt = radioValue(document.approvalsform.leadneimt);
	if ((neiotleadimt != "ukisa") && (neiotleadimt != "cemaas") && (neiotleadimt != "germanyimt") && (neiotleadimt != "nordic")) {
		changeChecks('disable');
	} else {
		changeChecks('enable');
	}
	if (imt == "ukisa") {

		neiotleadimt = radioValue(document.approvalsform.leadneimt);
		if ((neiotleadimt == "ukisa") || (ukisa == true)) {
			document.all.ukisacountries.style.display = '';
			document.approvalsform.ukisa.checked = true;
		} else {
			document.all.ukisacountries.style.display = 'none';
		}
		if (int == "n") {
			checkIMT('cemaas', 'y');
			checkIMT('germanyimt', 'y');
			checkIMT('nordic', 'y');
		}	
	}
	if (imt == "cemaas") {
		cemaas = document.approvalsform.cemaas.checked;
		neiotleadimt = radioValue(document.approvalsform.leadneimt);
		if ((neiotleadimt == "cemaas") || (cemaas == true)) {
			document.all.cemaascountries.style.display = '';
			document.approvalsform.cemaas.checked = true;
		} else {
			document.all.cemaascountries.style.display = 'none';
		}
		if (int == "n") {
			checkIMT('germanyimt', 'y');
			checkIMT('nordic', 'y');
			checkIMT('ukisa', 'y');
		}	
	}
	if (imt == "germanyimt") {
		germanyimt = document.approvalsform.germanyimt.checked;
		neiotleadimt = radioValue(document.approvalsform.leadneimt);
		if ((neiotleadimt == "germanyimt") || (germanyimt == true)) {
			document.all.germanycountries.style.display = '';
			document.approvalsform.germanyimt.checked = true;
		} else {
			document.all.germanycountries.style.display = 'none';
		}
		if (int == "n") {
			checkIMT('cemaas', 'y');
			checkIMT('nordic', 'y');
			checkIMT('ukisa', 'y');
		}	
	}
	if (imt == "nordic") {
		nordic = document.approvalsform.nordic.checked;
		neiotleadimt = radioValue(document.approvalsform.leadneimt);
		if ((neiotleadimt == "nordic") || (nordic == true)) {
			document.all.nordiccountries.style.display = '';
			document.approvalsform.nordic.checked = true;
		} else {
			document.all.nordiccountries.style.display = 'none';
		}
		if (int == "n") {
			checkIMT('cemaas',  'y');
			checkIMT('germanyimt', 'y');
			checkIMT('ukisa', 'y');
		}
	}
}

The function calls itself from within itself, but never with any possibility of entering a never-ending loop because of the second parameter.

Can you see any reason why Firefox alone (seemingly) won't run any JavaScript at all when this function is within the source code of the page? I've narrowed it down to this function by deleting the function from the code, and then everything else works perfectly in firefox.

Look forward to any help you are able to offer.

Thanks,
Dave.
 
By just glancing at your function, it is obvious that your use of document.all is not supported by mozilla. So, as a start, change all references using document.all.xxx, if it is a form element, to the more broadly supported standard document.formname.elements["xxx"].
 
Many of my other functions make use of the "document.all.rowid...." and they work fine. Where the elements are part of a form I have used document.approvalsform.name.

I don't disagree that my metholodogy leaves much to be desired, but this isn't why its not working I'm afraid.

Regards,
David.
 
The problem is your use of a reserved word for a variable name. Change the variable name and all will be well:
Code:
function checkIMT(imt, [b]int[/b]) {
Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
Genius - absolute genius! Thanks for your help, I'll know what to look for next time! Yesterday I spent 3 hours fixing some code only to realise I'd given a variable the same name as a function. And today this!

Awesome!

Thanks again,
David.
 
Good to see you got the problem solved... but still don't dismiss tsuji's suggestion... You really should remove all traces of "document.all" from your code in favour of better, and more standard, DOM methods. You code will be better for it.

Hope this helps,
Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
OK I'll go through it and try and clean up to be more compatible with other browsers like Mozilla. Obviously changing approach to not use this will take a bit of a rewrite but I agree is best way forward.

Thanks again for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top