tags:

views:

64

answers:

1

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??

+2  A: 

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).