Javascript that works in IE but not in FF, please advised

I have this javascript:

					<script language="Javascript">
						document.getElementById('cmp_ID').onchange = function () { updateQS('cmp_ID', document.getElementById('cmp_ID').options[document.getElementById('cmp_ID').selectedIndex].value); };
					</script>

called function:

<script language="Javascript">

	function updateQS(sName, sVal, arrClear)
	{
		var qs = self.location.search;
		
		if (arrClear)
		{
			for (var x = 0; x < arrClear.length; x++)
			{
				qs = eval('qs.replace(/[\\\\?|\\\\&]' + arrClear[x] + '=[^\\\\&]*/g, "")');
			}
		}
		
		if (qs == '')
		{
			qs = "?" + sName + "=" + escape(sVal);
		}
		else
		{
			if (qs.indexOf(sName) == -1)
			{
				qs = qs + "&" + sName + "=" + escape(sVal);
			}
			else
			{
				qs = eval('qs.replace(/(\\\\?|\\\\&)' + sName + '=([^\\\\&]*)/, "$1' + sName + '=' + escape(sVal) + '")');
			}
		}

		self.location.replace(self.location.href.replace(/\\?.*/g, "") + qs);
	}	

</script>

This works perfectly in IE but not in Firefox, please help asap. Thanks.

Rather than directly using onchange, why don’t you instead use the attachevent/addeventlistener methods to attach an onchange event?

How to do that?

The following article explains it pretty well, should be easy for you to understand once you’ve read it: http://www.quirksmode.org/js/events_advanced.html

Why? Do the onchange event does not work in Firefox?

I’m not sure why, but you may frequently run into problems with different browsers when you try to attach an event as you have been doing. Maybe someone else can shed more light on the inner workings of this…
You may also be facing some syntax issues; have you tried using onChange instead of onchange? I would still recommend addeventlistener though

I really need help some gurus here in Javascript…

Did you even try my suggestion or do you want me to actually write it out for you (I kinda assumed you would be able to do it after the clear explanations provided to you in the link…)?? For your own knowledge it would be better to do it yourself rather than copy/paste someone else’s source code.

Problem solved. :slight_smile:

I just forgot the id=“cmp_ID”. Thanks guys…