经典ASP。调用函数时出现问题

时间:2017-10-13 13:35:07

标签: javascript function vbscript asp-classic

我编写了一个经典的ASP函数,它读取MSSQL数据库,读取列值并更改HTML页面上的图像。这是我的代码 -

<script type="text/javascript" language="javascript">
function changeiconGREEN(image) {
    document.getElementById(image).src = "./Markers/green_circle.png";
} 
function changeiconRED(image) {
    document.getElementById(image).src = "./Markers/red_circle.png";
}
function changeiconYELLOW(image) {
    document.getElementById(image).src = "./Markers/yellow_circle.png";
}
 </script> 
 <% 
Function status(atname,id)
    Dim objRecordset
    Dim DB_CONNECTIONSTRING
    Dim i
    i = 0
    set DB_CONNECTIONSTRING = CreateObject("ADODB.connection")
    DB_CONNECTIONSTRING = "provider=SQLOLEDB;Data Source=SQLTEST\INSTANCE01;Initial Catalog=TEST_DB;UID=wug; PWD=wug"
    Set objRecordset = Server.CreateObject("ADODB.Recordset")
    objRecordset.Open "SELECT * FROM Device LEFT OUTER JOIN DeviceAttribute ON DeviceAttribute.nDeviceID = Device.nDeviceID WHERE Device.bRemoved = 0 AND  DeviceAttribute.sName = N'"&atname&"'  AND DeviceAttribute.sValue LIKE N'%"&atname&"%'", DB_CONNECTIONSTRING
    Do until objRecordset.eof
        if objrecordset.fields("nWorstStateID") >= 5 and objrecordset.fields("nWorstStateID") < 7 then
        response.write("<script type=""text/javascript"" language=""javascript"">" & vbcrlf)
        response.write("changeiconGREEN("""&id&""");" & vbcrlf)
        response.write("</script>" & vbcrlf)
   ElseIf objrecordset.fields("nWorstStateID") = 4 then
        i = 1   
   ElseIf objrecordset.fields("nWorstStateID") <= 3 and objrecordset.fields("nWorstStateID") > 7 then
        response.write("<script type=""text/javascript"" language=""javascript"">" & vbcrlf)
        response.write("changeiconRED("""&id&""");" & vbcrlf)
        response.write("</script>" & vbcrlf)
  end if
objRecordset.movenext
 loop
  if i = 1 then
        response.write("<script type=""text/javascript"" language=""javascript"">" & vbcrlf)
        response.write("changeiconYELLOW("""&id&""");" & vbcrlf)
        response.write("</script>" & vbcrlf)
        i=0
  end if
objRecordset.close
End Function

Call status(EDRMS,test)
%>

没有出现任何错误,但该功能似乎无法正常工作。当代码不在函数中并且变量被取出时,代码就可以工作。谁能发现问题?我已经盯着这几个小时了!

0 个答案:

没有答案