//JavaScript
function checkCountry(slctFild)
{
	if(slctFild.selectedIndex==1)
	{
		showStateSelectBox();
		hideProvinceSelectBox();
	}
	else
	{
		if(slctFild.selectedIndex==36)
		{
			hideStateSelectBox();
			showProvinceSelectBox();
		}
		else
		{
			document.getElementById("00N200000013FlZ").selectedIndex = 0; // ERROR gets thrown here!!!
			document.getElementById("00N200000013Flo").selectedIndex = 0;
			hideStateSelectBox();
			hideProvinceSelectBox();
		}
	}
}
//HTML Registraton Form

<select id="00N200000013FlU" title="Country" onchange="checkCountry(this)" name="00N200000013FlU">
	<option value="" selected="selected">--None--</option>
	<option value="United States of America">United States of America</option>
	...
</select>
                
<select id="00N200000013FlZ" title="State" name="00N200000013FlZ">
	<option value="" selected="selected">--None--</option>
	<option value="Alabama">Alabama</option>
	...
</select>
				
<select id="00N200000013Flo" title="Province" name="00N200000013Flo">
	<option value="" selected="selected">--None--</option>
	<option value="Alberta">Alberta</option>
	...
</select>

I get an error message every so often with this code.
'document.getElementById(...)' is null or not an object.
Ive added a comment to the line that i receive the error from. I cant seem to Find the error.

Any Help?
Thanx

I had a look at the code and tried it out, it works for me (though I did get rid of those "..." things you have. I was using firefox.

See thats the problem.

I have a Mailer set up, and every once it awhile i get an email with the error.

It wasnt a big deal until last week i got 5 in just a coupe of days.

I am unable to to reproduce the error, I guess thats why im have a hard time fixing it.

> I get an error message every so often with this code.
> 'document.getElementById(...)' is null or not an object.

Because there exists no element with the given ID. It looks as though the ID for your form elements are dynamically generated and hence the intermittent problem. A better way for setting the default drop down option would be to grab hold of all the SELECT items and set their selectedIndex property to zero (except for the SELECT element under consideration)

var sels = document.getElementsByTagName("SELECT");
for(var i = 0, maxI = sels.length; i < maxI; ++i) {
  var sel = sels[i];
  if(sel == slctFild)
    continue;  // exclude the current select element
  sel.selectedIndex = 0;
}

You just dumped huge compacted code portion to the forum. Sorry, I am not going to sit down and look at it. Also, please do not hijack other's thread. You should create your own.

Anybody could help me on this javascript which runs well in every browser except IE, I cant figure out why this strange error occurs. "null is null or not an object error"

        function fetchEventSource(src, callback) {
            alert(src);
            alert(callback);
            var prevViewName = view.name,
            prevDate = cloneDate(date),
            reportEvents = function(a) {
                if (prevViewName == view.name && +prevDate == +date  // protects from fast switching
                    && $.inArray(src, eventSources) != -1)               // makes sure source hasn't been removed
                {
                    alert(a.length);
                    for (var i = 1; i < a.length; i++) {
                        alert(a[i]);
                        normalizeEvent(a[i], options);

                        a[i].source = src;
                    }
                    events = events.concat(a);
                    if (callback) {
                        callback(a);
                    }
                }
            },
            reportEventsAndPop = function(a) {
                reportEvents(a);
                popLoading();
            };
            if (typeof src == 'string') {
                var params = {};
                params[options.startParam] = Math.round(eventStart.getTime() / 1000);
                params[options.endParam] = Math.round(eventEnd.getTime() / 1000);
                if (options.cacheParam) {
                    params[options.cacheParam] = (new Date()).getTime(); // TODO: deprecate cacheParam
                }
                pushLoading();
                $.ajax({
                    url: src,
                    dataType: 'json',
                    data: params,
                    cache: options.cacheParam || false, // don't let jquery prevent caching if cacheParam is being used
                    success: reportEventsAndPop
                });
            }
            else if ($.isFunction(src)) {
                pushLoading();
                src(cloneDate(eventStart), cloneDate(eventEnd), reportEventsAndPop);
            }
            else {
                reportEvents(src); // src is an array
            }
        }

Learn any JS library.
It will practically save you alot of pain with javascript ;)

it is simple you have to write a code after the elemet and then you can get the element by id (when the mashin know the element)

just add condition before you fetching value with document.getElementByID or getElementsByName. condition looks like: if(document.getElementById() && document.getElementById()!='undefined')
or
if(document.getElementsByName()[0] && document.getElementsByName()[0]!='undefined')


May help you to avoid the javascript errors while loading and with no value fetching from the controls.

Thanks,
Raghuram Reddy Gottimukkula
Adobe Certified ColdFusion Professional,
Hyderabad, India

3 years old thread!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.