2009-07-21 61 views
0

我使用這個JS腳本進行多國選擇,並從螢火蟲中得到一個錯誤。無效對象問題

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

相關的代碼是這樣的:

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]); 

完整的腳本can be found here

這是我如何使用它在我的HTML:

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

有什麼問題。我通過它正確的參數??

+0

由於您沒有報告錯誤,因此我們無法提供幫助。 – 2009-07-21 22:35:09

回答

2

從它出現粗略地看一眼,在

「變種selObj =的document.getElementById(idName);」

「document.getElementById(idName);」沒有返回任何東西(或者更確切地說返回null)。

我的猜測是idName的值不匹配。我將首先確定在document.getElement語句之前立即確定這個變量的值是什麼(我也會檢查非打印字符是否徹底)。