Tutorial :Null Object Problem


I am using this JS script for multiple country selection and I get an error from firebug.

selObj is null  [Break on this error] selObj.options[0] = new Option('Select Country','');  

The relevant code is this:

function populateCountry(idName) {   var countryLineArray = country.split('|'); // Split into lines     var selObj = document.getElementById(idName);     selObj.options[0] = new Option('Select Country','');   selObj.selectedIndex = 0;       for (var loop = 0; loop < countryLineArray.length; loop++) {     lineArray = countryLineArray[loop].split(':');     countryCode = TrimString(lineArray[0]);  

The full script can be found here.

This is how I use it in my HTML:

<select id="billCountrySelect" onchange="updateState('billCountrySelect')" name="bill_country">  

What is the problem. I am passing it correct parameters??


From a cursory glance it appears that in

" var selObj = document.getElementById(idName);"

"document.getElementById(idName);" is not returning anything (or more precisely returning null).

My guess is that the value of idName is not matching. I would start by ensuring exactly what is the value of this variable immediately before the document.getElement statement (I would also check for non-printing characters just to be thorough).

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »