<script language="javascript">
function showHint1(str){
if (str.length > 0){
var url="return1.asp?id="+str;
xmlHttp=GetXmlHttpObject(stateChange1);
xmlHttp.open("GET", url , true);
xmlHttp.send(null);
}
}
</script>
.
.
.....
<tr class="StyleNameB"> <td> </td>
<td align="right"><strong>หน่วยงานหลัก:</strong></td>
<td align="left"> <select name="oid1" onChange="showHint1(this.options[this.selectedIndex].value);">
<option value="0">เลือก</option>
<%set RS= Server.CreateObject("ADODB.Recordset")
sql1 = "SELECT * FROM site_organize1 order by code "
RS.Open sql1, MM_data_STRING ,1 ,1
for i=1 to RS.recordcount
if oid1="" then
if i=1 then oid1=RS("id") end if
end if
%>
<option value="<%=RS("id")%>" <%if num(oid1)=num(RS("id")) then response.Write("selected") end if%>><%=rs("name")%>[<%=rs("code")%>]</option>
<% rs.movenext
next
rs.close() : set rs=nothing
%>
</select></td>
</tr>
<tr class="StyleNameB"> <td> </td>
<td align="right"><strong>หน่วยงานรอง:</strong></td>
<td align="left"><div id="mypid"><select name="oid2">
<option value="0">เลือก</option>
<%set RS= Server.CreateObject("ADODB.Recordset")
sql1 = "SELECT * FROM site_organize2 where oid1="&num(oid1)&" order by code"
RS.Open sql1, MM_data_STRING ,1 ,1
for i=1 to RS.recordcount %>
<option value="<%=RS("id")%>" <%if num(oid2)=num(RS("id")) then response.Write("selected") end if%>><%=rs("name")%>[<%=rs("code")%>]</option>
<% rs.movenext
next
rs.close() : set rs=nothing
%>
</select>
</div></td></tr>
Code (JavaScript)
var xmlHttp
function stateChange1(){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
document.getElementById("mypid").innerHTML=xmlHttp.responseText
}
}
function GetXmlHttpObject(handler)
{
var objXmlHttp=null
if (navigator.userAgent.indexOf("Opera")>=0)
{
alert("This example doesn't work in Opera")
return
}
if (navigator.userAgent.indexOf("MSIE")>=0)
{
var strName="Msxml2.XMLHTTP"
if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
{
strName="Microsoft.XMLHTTP"
}
try
{
objXmlHttp=new ActiveXObject(strName)
objXmlHttp.onreadystatechange=handler
return objXmlHttp
}
catch(e)
{
alert("Error. Scripting for ActiveX might be disabled")
return
}
}
if (navigator.userAgent.indexOf("Mozilla")>=0)
{
objXmlHttp=new XMLHttpRequest()
objXmlHttp.onload=handler
objXmlHttp.onerror=handler
return objXmlHttp
}
}