el codigo es el sgte, quite los comentarios que tenia el codigo ya que de porsi el codigo es extenso mas los comentarios es como que se van a acordar de toda mi familia jajaj, igualmente si quieren ver los comentarios pueden acceder al link que se encuentra mas arriba, besos.
</HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
function clearcombo(elem){
var i;
for (i = elem.options.length; i >= 0; i--) elem.options[i] = null;
elem.selectedIndex = -1;
}
function populatecombo2(elem, index){
if (array1.length >= index){
if (array1[index]){
for (var i = 0; i < array1[index].length; i= i + 2){
elem.options[elem.options.length] = new Option(array1[index][i + 1], array1[index][i]);
}
}
else{
elem.options[elem.options.length] = new Option("[none available]", 0);
}
}
else{
elem.options[elem.options.length] = new Option("[none available]", 0);
}
}
function populatecombo3(elem, index){
if (array2.length >= index){
if (array2[index]){
for (var i = 0; i < array2[index].length; i= i + 2){
elem.options[elem.options.length] = new Option(array2[index][i + 1], array2[index][i]);
}
}
else{
elem.options[elem.options.length] = new Option("[none available]", 0);
}
}
else{
elem.options[elem.options.length] = new Option("[none available]", 0);
}
}
function clickcombo(nWhich,elem1,elem2,elem3){
if (nWhich == 1){
clearcombo(elem2);
clearcombo(elem3);
populatecombo2(elem2, elem1[elem1.selectedIndex].value);
}
if (nWhich == 2){
clearcombo(elem3);
populatecombo3(elem3, elem2[elem2.selectedIndex].value);
}
return true;
}
// -->
</script>
<BODY>
<%
Dim Conn
Dim sQuery
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "pubs", "sa", ""
sQuery = "SELECT p.pub_id, p.pub_name, t.title_id, t.title AS title_name, " & _
"ta.au_id, a.au_fname + ' ' + a.au_lname AS au_name " & vbCrlf & _
"FROM publishers p, titles t, titleauthor ta, authors a " & vbCrlf & _
"WHERE p.pub_id=t.pub_id " & vbCrlf & _
" AND ta.title_id=t.title_id " & vbCrlf & _
" AND a.au_id = ta.au_id " & vbCrlf & _
"ORDER BY pub_name, title, ta.au_ord "
%>
<FORM id=form1 name=form1>
<%
Response.Write TripleLinkedList(Conn, sQuery, "fieldname", 10, "pub_name", "title_name", "au_name", "au_id")
Conn.Close
Set Conn = Nothing
%>
<P>
<INPUT TYPE=SUBMIT NAME="foo" VALUE="Buy This Car!">
</FORM>
</BODY>
</HTML>
<%
Function TripleLinkedList(oCon, sQuery, sFormFieldName, nSize, sDBField1, sDBField2, sDBField3, sDBFieldResult)
Dim sTemp ' general-purpose temp variable
Dim sScript ' bucket for holding the script structure
Dim sSelect ' bucket for the <SELECT> statement
Dim sArray1 ' bucket to store the DBField2 array
Dim nField1 ' counter for the primary array
Dim sArray2 ' bucket to store the DBField3 array
Dim nField2 ' counter for the secondary array
Dim rs ' recordset
Dim sLastVal1 ' comparison string to test for record changes
Dim sLastVal2 ' comparison string to test for record changes
On Error Resume Next
If Not IsObject(oCon) Then
sScript = "error processing triplelist -- need a connection object."
ElseIf oCon.State <> 1 Then
If Err.number <> 0 Then
sScript = "error processing triplelist -- invalid connection object."
Else
sScript = "error processing triplelist -- connection is not open."
End If
Else
Set rs = oCon.Execute(sQuery)
If Err.number <> 0 Then
sScript = "error processing query. Error " & Hex(Err.number) & ": " & Err.Description
ElseIf rs.EOF Then
sScript = "no records found -- seems wrong"
Else
On Error Goto 0
sScript = "<SCR" & "IPT LANGUAGE=""JavaScript"">" & vbCrlf
sScript = sScript & "var array1 = new Array();" & vbCrlf
sScript = sScript & "var array2 = new Array();" & vbCrlf
sSelect = "<SELECT NAME=""" & sFormFieldName & "1"" SIZE=""" & nSize & _
""" ONCHANGE=""return(clickcombo(1,document.forms[0]." & _
sFormFieldName & "1,document.forms[0]." & sFormFieldName & _
"2,document.forms[0]." & sFormFieldName & "3));"">" & vbCrlf
sLastVal1 = "empty"
Do Until rs.EOF
If rs(sDBField1) <> sLastVal1 Then
If Right(sArray1, 3) = "," & vbCrlf Then
sArray1 = Left(sArray1, Len(sArray1) - 3)
End If
If Len(sArray1) > 0 Then
sArray1 = sArray1 & ");" & vbCrlf
End If
nField1 = nField1 + 1
sLastVal1 = rs(sDBField1)
sSelect = sSelect & "<OPTION VALUE=" & nField1 & ">" & sLastVal1 & "</OPTION>"
sArray1 = sArray1 & "array1[" & nField1 & "] = new Array(" & vbCrlf
nField2 = 0
sLastVal2 = "empty"
End If
If sLastVal2 <> rs(sDBField2) Then
If Right(sArray2, 3) = "," & vbCrlf Then
sArray2 = Left(sArray2, Len(sArray2) - 3)
End If
If Len(sArray2) > 0 Then
sArray2 = sArray2 & ");" & vbCrlf
End If
sLastVal2 = rs(sDBField2)
nField2 = nField2 + 1
sArray1 = sArray1 & " " & 1000 * nField1 + nField2 & ",""" & sLastVal2 & """," & vbCrlf
sArray2 = sArray2 & "// values for " & sLastVal2 & vbCrlf
sArray2 = sArray2 & "array2[" & 1000 * nField1 + nField2 & "] = new Array(" & vbCrlf
End If
sArray2 = sArray2 & " " & rs(sDBFieldResult) & ",""" & rs(sDBField3) & """," & vbCrlf
rs.MoveNext ' move on to the next record...
Loop
If Right(sArray2, 3) = "," & vbCrlf Then
sArray2 = Left(sArray2, Len(sArray2) - 3)
End If
If Len(sArray2) > 0 Then
sArray2 = sArray2 & ");" & vbCrlf
End If
If Right(sArray1, 3) = "," & vbCrlf Then
sArray1 = Left(sArray1, Len(sArray1) - 3)
End If
If Len(sArray1) > 0 Then
sArray1 = sArray1 & ");" & vbCrlf
End If
sSelect = sSelect & "</SELECT>" & vbCrlf
sSelect = sSelect & "<SELECT NAME=""" & sFormFieldName & "2"" SIZE=""" & nSize & _
""" ONCHANGE=""return(clickcombo(2,document.forms[0]." & sFormFieldName & _
"1,document.forms[0]." & sFormFieldName & "2,document.forms[0]." & _
sFormFieldName & "3));""><OPTION>Nothing Selected</OPTION></SELECT>" & vbCrlf
sSelect = sSelect & "<SELECT NAME=""" & sFormFieldName & "3"" SIZE=""" & nSize & _
"""><OPTION>Nothing Selected</OPTION></SELECT>" & vbCrlf
sScript = sSelect & vbCrlf & _
sScript & vbCrlf & _
sArray1 & vbCrlf & _
sArray2 & vbCrlf & _
"</SCR" & "IPT>" & vbCrlf
End If
rs.Close
Set rs = Nothing
End If
TripleLinkedList = sScript
End Function
%> |