2013-05-08 80 views
0

所以我有這個網頁代碼,它在Firefox中工作(有點),但只有選擇在IE8中工作。爲了使它在Firefox中工作,警報(null)必須在那裏,否則將不會轉到hrefmyloc == "MySrch"。我沒有收到任何反饋錯誤,這真是令人困惑。JavaScript功能有時失敗onchange

SqlStr = "Select DISTINCT Unit From Employee Where PhoneBook = 1 Order by Unit;" 
Set UniNme = Connection.Execute(SqlStr) 
Response.Write "<select id='Unit' onChange='Change(this.id)'>" 
Response.Write "<option value=''>Choose Unit</option><br>" 
Response.Write "<option value='Everyone'>Everyone</option><br>" 
Do While Not UniNme.EOF 
Response.Write "<option value='"&UniNme("Unit")&"'>"&UniNme("Unit")&"</option><br>" 
UniNme.MoveNext 
Loop 
Response.Write "</select><br>" 

Response.Write "Name Search: <input type='text' id='MySrch' onChange='Change(this.id)'>" 

JavaScript函數是

function Change(myloc) { 
if (myloc == "Unit") { 
var myindex = document.getElementById(myloc).selectedIndex; 
myvalue = document.getElementsByTagName("option")[myindex].value; 
} else { 
var myvalue = document.getElementById(myloc).value; 
} 

document.cookie = "Temp1="+escape(myloc); 
document.cookie = "Temp2="+escape(myvalue); 

document.location.href="AEmployees.asp?action=Change"; 

alert(null); 
} 

回答

0

看一看myvalue的變量的範圍。它在這裏

else { 
var myvalue = document.getElementById(myloc).value; 
} 

當地的知名度,可能不會引起問題,但它是有潛在危險的代碼