I don't understand why don't work.
Can anyone help me?
Thanks,
Gui Reis
<!-- #include virtual="/conteudos/incSys
tem.asp"--
>
<%
set conn=server.createobject("
ADODB.Conn
ection")
conn.open connection
%>
<html>
<head>
<title>Populate Select Options</title>
</head>
<body>
<script language=Javascript>
<%
Dim count
Dim DistID
Dim DistTXT
count = 0
SQL = "SELECT dist_code, dist_descricao FROM bvu_distrito"
set rs = Conn.Execute(SQL)
Do Until rs.eof
if count = 0 then
DistID = rs("dist_code")
DistTXT = chr(34) & rs("dist_descricao") & chr(34)
else
DistID = rs("dist_code") & "," & DistID
DistTXT = chr(34) & rs("dist_descricao") & chr(34) & "," & DistTXT
end if
count = count + 1
rs.movenext
Loop
DistID = DistID & ",-1"
DistTXT = DistTXT & ",-1"
rs.close
set rs = nothing
%>
// now populate the Javascript variables
var ArrayDistID = new Array(<%=DistID%>);
var ArrayDistTXT = new Array(<%=DistTXT%>);
// now show them so you know this works!
alert(ArrayDistID + '\n' + ArrayDistTXT);
</script>
<script language="javascript">
function ManageStates(value)
{
var disp = "block";
if (value.match ("USA") == null){
disp = "none";
}
var states = document.MyForm.Conuntry_S
tates;
if (states != null) {
states.style.display = disp;
}
}
function ManageList (value) {
var USAStateList = new Array('FL', 'NY', 'CA');
var CANStateList = new Array('Can_State1', 'Can_state2');
var UKRStateList = null;
var stateList = null;
//
// Clean the current list
//
for (var i=0; i < document.MyForm.Conuntry_S
tates.leng
th; i++)
{
document.MyForm.Conuntry_S
tates.opti
ons[i]=nul
l;
}
document.MyForm.Conuntry_S
tates.leng
th = 0;
//
// Evaluate and assign the list
//
if (value.match ("USA") != null) {
stateList = USAStateList;
}
if (value.match ("CAN") != null) {
stateList = CANStateList;
}
if (value.match ("UKR") != null) {
stateList = UKRStateList;
}
//
// Update the Option Value, Text, Length and Display
//
if (stateList != null) {
for (var j=0; j < stateList.length; j++)
{
//alert (" State " + stateList[j]);
eval ("var optionText"+j+" = new Option(stateList[j])")
eval ("var optionValue"+j+" = stateList[j]")
eval ("document.MyForm.Conuntry
_States.op
tions[j] = optionText" + j)
eval ("document.MyForm.Conuntry
_States.op
tions[j].v
alue = optionValue" + j)
}
document.MyForm.Conuntry_S
tates.leng
th = stateList.length;
document.MyForm.Conuntry_S
tates.styl
e.display = "block";
}
else {
document.MyForm.Conuntry_S
tates.styl
e.display = "none";
}
}
</script>
<form name="MyForm">
<table>
<tr>
<th align="left">
<select name="Country" onChange="ManageList(docum
ent.MyForm
.Country.v
alue);">
<option value="CAN">Canada</option
>
<option value="UKR">Ukraine</optio
n>
<option value="USA" selected>United States of America</option>
</select>
</th>
</tr>
<tr>
<th align="left">
<select name="Conuntry_States">
<option value="FL">Florida</option
>
<option value="CA">California</opt
ion>
<option value="NY">New York</option>
</select>
</th>
</tr>
</table>
</form>
</body>
</html>
Start Free Trial