...

View Full Version : Problems with this Dependant Dropdowns Script



tcadieux
08-09-2006, 02:36 AM
The below code works, but only in part..I know what i'm doing wrong appears in the second set of code i posted, my Arrays aren't getting Unique ids...but i can;t for the life of me think of an appropriate way to assign them?




<%
'Get all the Designates
sDesignate="SELECT UnitDesignate.UnitDesignateID, UnitDesignate.UDesignate_E "
sDesignate=sDesignate & " FROM UnitDesignate"
sDesignate=sDesignate & " ORDER BY UDesignate_E ASC"

Set cnnGetRows = Server.CreateObject("ADODB.Connection")
cnnGetRows.Open = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath("../Access/units.mdb")

Set rstGetRows = cnnGetRows.Execute(sDesignate)
IF NOT rstGetRows.EOF THEN
iDesignate=rstGetRows.fields.count -1
arrDesignate = rstGetRows.GetRows()
DesignateID = 0
DesignateName = 1
END IF

rstGetRows.Close
Set rstGetRows = Nothing

%>
<HEAD>

<script type="text/javascript">
<!--

var arrItems1 = new Array();
var arrItemsGrp1 = new Array();

<%
if isarray(arrDesignate) then
EndDesignate=UBOUND(arrDesignate, 2)
FOR intDesignate=LBOUND(arrDesignate, 2) TO UBOUND(arrDesignate, 2)

sUnitDesignate=" SELECT UnitDesingnateNO.UnitDesignateNO_E, UnitDesingnateNO.UDesignate_OF"
sUnitDesignate=sUnitDesignate & " FROM UnitDesingnateNO"
sUnitDesignate=sUnitDesignate & " WHERE (((UnitDesingnateNO.UDesignate_OF)="&arrDesignate(DesignateID, intDesignate)&"));"

Set cnnGetRows = Server.CreateObject("ADODB.Connection")
cnnGetRows.Open = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath("../Access/units.mdb")

Set rstGetRows = cnnGetRows.Execute(sUnitDesignate)
IF NOT rstGetRows.EOF THEN
iUnitDesignate=rstGetRows.fields.count -1
arrUnitDesignate = rstGetRows.GetRows()
UnitDesignateID = 0
UnitDesignateName = 1
END IF

rstGetRows.Close
Set rstGetRows = Nothing


'arrItems1[3] = "Truck";
'arrItemsGrp1[3] = 1;
'arrItems1[4] = "Train";
'arrItemsGrp1[4] = 1;
'arrItems1[5] = "Car";
'arrItemsGrp1[5] = 1;

FOR iUnitDesignate=LBOUND(arrUnitDesignate, 2) TO UBOUND(arrUnitDesignate, 2)


response.Write("arrItems1["& arrDesignate(DesignateID, intDesignate) &"] =" )
'response.Write("arrItems1["& iUnitDesignate &"] =" )
response.Write(Chr(34) &arrUnitDesignate(UnitDesignateID, iUnitDesignate)& Chr(34))
response.Write(";" & vbCrLf)
response.Write("arrItemsGrp1["& arrDesignate(DesignateID, intDesignate) &"] =" )
'response.Write("arrItemsGrp1["& iUnitDesignate &"] =" )
response.Write(arrDesignate(DesignateID, intDesignate))
response.Write( vbCrLf)


NEXT

NEXT


End if
%>

var arrItems2 = new Array();
var arrItemsGrp2 = new Array();


function selectChange(control, controlToPopulate, ItemArray, GroupArray) {
var myEle ;
var x ;
// Empty the second drop down box of any choices
for (var q=controlToPopulate.options.length;q>=0;q--) controlToPopulate.options[q]=null;
if (control.name == "firstChoice") {
// Empty the third drop down box of any choices
//for (var q=form.thirdChoice.options.length;q>=0;q--) form.thirdChoice.options[q] = null;
}
// ADD Default Choice - in case there are no values
myEle = document.createElement("option") ;
myEle.value = 0 ;
myEle.text = "[SELECT]" ;
// controlToPopulate.add(myEle) ;
controlToPopulate.appendChild(myEle)
// Now loop through the array of individual items
// Any containing the same child id are added to
// the second dropdown box
for ( x = 0 ; x < ItemArray.length ; x++ ) {
if ( GroupArray[x] == control.value ) {
myEle = document.createElement("option") ;
//myEle.value = x ;
myEle.setAttribute('value',x);
// myEle.text = ItemArray[x] ;
var txt = document.createTextNode(ItemArray[x]);
myEle.appendChild(txt)
// controlToPopulate.add(myEle) ;
controlToPopulate.appendChild(myEle)
}
}
}

function selectChange(control, controlToPopulate, ItemArray, GroupArray) {
var myEle ;
var x ;
// Empty the second drop down box of any choices
for (var q=controlToPopulate.options.length;q>=0;q--) controlToPopulate.options[q]=null;
if (control.name == "firstChoice") {
// Empty the third drop down box of any choices
//for (var q=form.thirdChoice.options.length;q>=0;q--) form.thirdChoice.options[q] = null;
}
// ADD Default Choice - in case there are no values
myEle=document.createElement("option");
theText=document.createTextNode("[SELECT]");
myEle.appendChild(theText);
myEle.setAttribute("value","0");
controlToPopulate.appendChild(myEle);
// Now loop through the array of individual items
// Any containing the same child id are added to
// the second dropdown box
for ( x = 0 ; x < ItemArray.length ; x++ ) {
if ( GroupArray[x] == control.value ) {
myEle = document.createElement("option") ;
//myEle.value = x ;
myEle.setAttribute("value",x);
// myEle.text = ItemArray[x] ;
var txt = document.createTextNode(ItemArray[x]);
myEle.appendChild(txt)
// controlToPopulate.add(myEle) ;
controlToPopulate.appendChild(myEle)
}
}
}
// -->
</script>
</HEAD>


<BODY>

<form name=form>
<table align="center">
<tr>
<td>
<select id="firstChoice" name="firstChoice" onChange="selectChange(this, form.secondChoice, arrItems1, arrItemsGrp1);">
<%

if isarray(arrDesignate) then
endDesignate=UBOUND(arrDesignate, 2)
FOR iDesignate=LBOUND(arrDesignate, 2) TO UBOUND(arrDesignate, 2) 'Display Products
response.Write("<option value='"&uCase(arrDesignate(DesignateID, iDesignate))&"'")
IF arrDesignate(Designate, iDesignate)= UnitDesignateID THEN
Response.Write("SELECTED")
ELSE

END IF
response.Write(">")
response.Write(uCase(arrDesignate(DesignateName, iDesignate))&"</option>"& vbCrLf)
NEXT 'Display Category
response.Write (");")
End if 'Display Category
%>
</select>
</td><td>
<select id="secondChoice" name="secondChoice">
</select>

</td>
</tr>
</table>
</form>




Here's the resulting Script




<HEAD>

<script type="text/javascript">
<!--

var arrItems1 = new Array();
var arrItemsGrp1 = new Array();

arrItems1[0] ="1 ASG";
arrItemsGrp1[0] =3
arrItems1[1] ="2 ASG";
arrItemsGrp1[1] =3
arrItems1[1] ="Demo Team";
arrItemsGrp1[1] =1
arrItems1[2] ="LFCA (Reserves)";
arrItemsGrp1[2] =1
arrItems1[0] ="38 CBG";
arrItemsGrp1[0] =4
arrItems1[1] ="39 CBG";
arrItemsGrp1[1] =4
arrItems1[2] ="41 CBG";
arrItemsGrp1[2] =4
arrItems1[3] ="31 CBG";
arrItemsGrp1[3] =4
arrItems1[4] ="32 CBG";
arrItemsGrp1[4] =4
arrItems1[5] ="33 CBG";
arrItemsGrp1[5] =4
arrItems1[6] ="34 CBG";
arrItemsGrp1[6] =4
arrItems1[7] ="35 CBG";
arrItemsGrp1[7] =4
arrItems1[8] ="36 CBG";
arrItemsGrp1[8] =4
arrItems1[9] ="37 CBG";
arrItemsGrp1[9] =4
arrItems1[0] ="1 CMBG";
arrItemsGrp1[0] =2
arrItems1[1] ="2 CMBG";
arrItemsGrp1[1] =2
arrItems1[2] ="5 CMBG";
arrItemsGrp1[2] =2


var arrItems2 = new Array();
var arrItemsGrp2 = new Array();


function selectChange(control, controlToPopulate, ItemArray, GroupArray) {
var myEle ;
var x ;
// Empty the second drop down box of any choices
for (var q=controlToPopulate.options.length;q>=0;q--) controlToPopulate.options[q]=null;
if (control.name == "firstChoice") {
// Empty the third drop down box of any choices
//for (var q=form.thirdChoice.options.length;q>=0;q--) form.thirdChoice.options[q] = null;
}
// ADD Default Choice - in case there are no values
myEle = document.createElement("option") ;
myEle.value = 0 ;
myEle.text = "[SELECT]" ;
// controlToPopulate.add(myEle) ;
controlToPopulate.appendChild(myEle)
// Now loop through the array of individual items
// Any containing the same child id are added to
// the second dropdown box
for ( x = 0 ; x < ItemArray.length ; x++ ) {
if ( GroupArray[x] == control.value ) {
myEle = document.createElement("option") ;
//myEle.value = x ;
myEle.setAttribute('value',x);
// myEle.text = ItemArray[x] ;
var txt = document.createTextNode(ItemArray[x]);
myEle.appendChild(txt)
// controlToPopulate.add(myEle) ;
controlToPopulate.appendChild(myEle)
}
}
}

function selectChange(control, controlToPopulate, ItemArray, GroupArray) {
var myEle ;
var x ;
// Empty the second drop down box of any choices
for (var q=controlToPopulate.options.length;q>=0;q--) controlToPopulate.options[q]=null;
if (control.name == "firstChoice") {
// Empty the third drop down box of any choices
//for (var q=form.thirdChoice.options.length;q>=0;q--) form.thirdChoice.options[q] = null;
}
// ADD Default Choice - in case there are no values
myEle=document.createElement("option");
theText=document.createTextNode("[SELECT]");
myEle.appendChild(theText);
myEle.setAttribute("value","0");
controlToPopulate.appendChild(myEle);
// Now loop through the array of individual items
// Any containing the same child id are added to
// the second dropdown box
for ( x = 0 ; x < ItemArray.length ; x++ ) {
if ( GroupArray[x] == control.value ) {
myEle = document.createElement("option") ;
//myEle.value = x ;
myEle.setAttribute("value",x);
// myEle.text = ItemArray[x] ;
var txt = document.createTextNode(ItemArray[x]);
myEle.appendChild(txt)
// controlToPopulate.add(myEle) ;
controlToPopulate.appendChild(myEle)
}
}
}
// -->
</script>
</HEAD>


<BODY>

<form name=form>
<table align="center">
<tr>
<td>
<select id="firstChoice" name="firstChoice" onChange="selectChange(this, form.secondChoice, arrItems1, arrItemsGrp1);">
<option value='3'>ASG</option>
<option value='1'>BASE</option>
<option value='4'>CBG</option>
<option value='2'>CMBG</option>
);
</select>
</td><td>
<select id="secondChoice" name="secondChoice">
</select>

</td>
</tr>
</table>
</form>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum