sr_aneesh
June 5th, 2005, 05:01 AM
i am making a dependent dropdownbox. For Eg : if i select a education qualification(Parent List Box) the related specilisation is displayed in the Specialisation Drop box (child List box). The Table structure of are as follows :
Main Table
id
NameofCandidate
Qualification(id of qualification table)
Specvialisation (id of special Table)
Qualification Table
id
Title(Qualificartion like, B.A, M.A,B.E.....etc.)
Special Table
id
Title (specialisation like Economics,Mechanic,Computer....etc.)
Subid(id from the qualification table)
suppose a candidate "X" has done B.E.(Qualification) in Electronics(specialisation).. the data in the main table will be (1,'Tom',9,8)
the programm works fine but what if i want to edit a record once its been saved in the main table
What if he the record has to be edited for changing the Qualification or Specilisation. when a record for a particlar candiate is edited is should display the saved values..
for eg : when the record is edited of the Candidate X the saved education and specilisation should be selected automatically.....
Looking forward for the solution ...
Thanx in advance
here is my code...
<%
function getselectedval(optval,origval)
if optval = origval then
getselectedval = "selected"
else
getselectedval = ""
end if
end function
%>
<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.open Application("conn")
%>
<%if Request("id")<>"" then%>
<%
sql="select * from test where id="&Request("id")
set rs=conn.Execute(sql)
%>
<%end if%>
<%
Dim rsMain
Dim rsMain_numRows
Set rsMain = Server.CreateObject("ADODB.Recordset")
rsMain.ActiveConnection = conn
rsMain.Source = "SELECT * FROM qualification ORDER BY title ASC"
rsMain.CursorType = 0
rsMain.CursorLocation = 2
rsMain.LockType = 1
rsMain.Open()
rsMain_numRows = 0
%>
<%
Dim rsSub
Dim rsSub_numRows
Set rsSub = Server.CreateObject("ADODB.Recordset")
rsSub.ActiveConnection = conn
rsSub.Source = "SELECT id,subid,title FROM special ORDER BY title ASC"
rsSub.CursorType = 0
rsSub.CursorLocation = 2
rsSub.LockType = 1
rsSub.Open()
rsSub_numRows = 0
%>
<html>
<head>
<title>Client Side Dependent List Menu</title>
<script language="JavaScript">
<!--
var arrDynaList = new Array();
var arrDL1 = new Array();
arrDL1[1] = "select1"; // Name of parent list box
arrDL1[2] = "form1"; // Name of form containing parent list box
arrDL1[3] = "select2"; // Name of child list box
arrDL1[4] = "form1"; // Name of form containing child list box
arrDL1[5] = arrDynaList; // No need to do anything here
<%
Dim txtDynaListRelation, txtDynaListLabel, txtDynaListValue, oDynaListRS
txtDynaListRelation = "subid" ' Name of recordset field relating to parent
txtDynaListLabel = "title" ' Name of recordset field for child Item Label
txtDynaListValue = "id" ' Name of recordset field for child Value
Set oDynaListRS = rsSub ' Name of child list box recordset
Dim varDynaList
varDynaList = -1
Dim varMaxWidth
varMaxWidth = "1"
Dim varCheckGroup
varCheckGroup = oDynaListRS.Fields.Item(txtDynaListRelation).Value
Dim varCheckLength
varCheckLength = 0
Dim varMaxLength
varMaxLength = 0
While (NOT oDynaListRS.EOF)
If (varCheckGroup <> oDynaListRS.Fields.Item(txtDynaListRelation).Value) Then
If (varCheckLength > varMaxLength) Then
varMaxLength = varCheckLength
End If
varCheckLength = 0
End If
%>
arrDynaList[<%=(varDynaList+1)%>] = "<%=(oDynaListRS.Fields.Item(txtDynaListRelation).Value)%>"
arrDynaList[<%=(varDynaList+2)%>] = "<%=(oDynaListRS.Fields.Item(txtDynaListLabel).Value)%>"
arrDynaList[<%=(varDynaList+3)%>] = "<%=(oDynaListRS.Fields.Item(txtDynaListValue).Value)%>"
<%
If (len(oDynaListRS.Fields.Item(txtDynaListLabel).Value) > len(varMaxWidth)) Then
varMaxWidth = oDynaListRS.Fields.Item(txtDynaListLabel).Value
End If
varCheckLength = varCheckLength + 1
varDynaList = varDynaList + 3
oDynaListRS.MoveNext()
Wend
If (varCheckLength > varMaxLength) Then
varMaxLength = varCheckLength
End If
%>
//-->
</script>
<!-- End of object/array definitions, beginning of generic functions -->
<script language="JavaScript">
<!--
function setDynaList(arrDL){
var oList1 = document.forms[arrDL[2]].elements[arrDL[1]];
var oList2 = document.forms[arrDL[4]].elements[arrDL[3]];
var arrList = arrDL[5];
clearDynaList(oList2);
if (oList1.selectedIndex == -1){
oList1.selectedIndex = 0;
}
populateDynaList(oList2, oList1[oList1.selectedIndex].value, arrList);
return true;
}
function clearDynaList(oList){
for (var i = oList.options.length; i >= 0; i--){
oList.options[i] = null;
}
oList.selectedIndex = -1;
}
function populateDynaList(oList, nIndex, aArray){
oList[oList.length]= new Option("Please Select");
for (var i = 0; i < aArray.length; i= i + 3){
if (aArray[i] == nIndex){
oList.options[oList.options.length] = new Option(aArray[i + 1], aArray[i + 2]);
}
}
if (oList.options.length == 1){
oList.options[oList.options.length] = new Option(":: No SubCategories Available ::");
}
oList.selectedIndex = 0;
}
//-->
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000" onLoad="setDynaList(arrDL1)">
<p> </p>
<form name="form1" method="post" action="">
<table width="650" border="0" cellspacing="0" cellpadding="5" align="center">
<tr>
<td align="center"> <select name="select1" onChange="setDynaList(arrDL1)" >
<%
While (NOT rsMain.EOF)
%>
<option <%if Request("id")<>"" then%><%=getselectedval(rsMain.Fields.Item("id").Value,rs(1))%><%end if%> value="<%=(rsMain.Fields.Item("id").Value)%>"><%=(rsMain.Fields.Item("title").Value)%></option>
<%
rsMain.MoveNext()
Wend
If (rsMain.CursorType > 0) Then
rsMain.MoveFirst
Else
rsMain.Requery
End If
%>
</select> </td>
<td align="center">
<select name="select2" >
<%if Request("id")<>"" then
While (NOT rssub.EOF)
%>
<option <%=getselectedval(rssub.Fields.Item("id").Value,rs(2))%>></option>
<%
rssub.MoveNext()
Wend
If (rssub.CursorType > 0) Then
rssub.MoveFirst
Else
rssub.Requery
End If
%>
<%end if%>
</select>
</td>
</tr>
<tr>
</table>
</form>
<p> </p>
<p> </p>
</body>
</html>
<%
rsMain.Close()
Set rsMain = Nothing
%>
<%
rsSub.Close()
Set rsSub = Nothing
%>
Main Table
id
NameofCandidate
Qualification(id of qualification table)
Specvialisation (id of special Table)
Qualification Table
id
Title(Qualificartion like, B.A, M.A,B.E.....etc.)
Special Table
id
Title (specialisation like Economics,Mechanic,Computer....etc.)
Subid(id from the qualification table)
suppose a candidate "X" has done B.E.(Qualification) in Electronics(specialisation).. the data in the main table will be (1,'Tom',9,8)
the programm works fine but what if i want to edit a record once its been saved in the main table
What if he the record has to be edited for changing the Qualification or Specilisation. when a record for a particlar candiate is edited is should display the saved values..
for eg : when the record is edited of the Candidate X the saved education and specilisation should be selected automatically.....
Looking forward for the solution ...
Thanx in advance
here is my code...
<%
function getselectedval(optval,origval)
if optval = origval then
getselectedval = "selected"
else
getselectedval = ""
end if
end function
%>
<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.open Application("conn")
%>
<%if Request("id")<>"" then%>
<%
sql="select * from test where id="&Request("id")
set rs=conn.Execute(sql)
%>
<%end if%>
<%
Dim rsMain
Dim rsMain_numRows
Set rsMain = Server.CreateObject("ADODB.Recordset")
rsMain.ActiveConnection = conn
rsMain.Source = "SELECT * FROM qualification ORDER BY title ASC"
rsMain.CursorType = 0
rsMain.CursorLocation = 2
rsMain.LockType = 1
rsMain.Open()
rsMain_numRows = 0
%>
<%
Dim rsSub
Dim rsSub_numRows
Set rsSub = Server.CreateObject("ADODB.Recordset")
rsSub.ActiveConnection = conn
rsSub.Source = "SELECT id,subid,title FROM special ORDER BY title ASC"
rsSub.CursorType = 0
rsSub.CursorLocation = 2
rsSub.LockType = 1
rsSub.Open()
rsSub_numRows = 0
%>
<html>
<head>
<title>Client Side Dependent List Menu</title>
<script language="JavaScript">
<!--
var arrDynaList = new Array();
var arrDL1 = new Array();
arrDL1[1] = "select1"; // Name of parent list box
arrDL1[2] = "form1"; // Name of form containing parent list box
arrDL1[3] = "select2"; // Name of child list box
arrDL1[4] = "form1"; // Name of form containing child list box
arrDL1[5] = arrDynaList; // No need to do anything here
<%
Dim txtDynaListRelation, txtDynaListLabel, txtDynaListValue, oDynaListRS
txtDynaListRelation = "subid" ' Name of recordset field relating to parent
txtDynaListLabel = "title" ' Name of recordset field for child Item Label
txtDynaListValue = "id" ' Name of recordset field for child Value
Set oDynaListRS = rsSub ' Name of child list box recordset
Dim varDynaList
varDynaList = -1
Dim varMaxWidth
varMaxWidth = "1"
Dim varCheckGroup
varCheckGroup = oDynaListRS.Fields.Item(txtDynaListRelation).Value
Dim varCheckLength
varCheckLength = 0
Dim varMaxLength
varMaxLength = 0
While (NOT oDynaListRS.EOF)
If (varCheckGroup <> oDynaListRS.Fields.Item(txtDynaListRelation).Value) Then
If (varCheckLength > varMaxLength) Then
varMaxLength = varCheckLength
End If
varCheckLength = 0
End If
%>
arrDynaList[<%=(varDynaList+1)%>] = "<%=(oDynaListRS.Fields.Item(txtDynaListRelation).Value)%>"
arrDynaList[<%=(varDynaList+2)%>] = "<%=(oDynaListRS.Fields.Item(txtDynaListLabel).Value)%>"
arrDynaList[<%=(varDynaList+3)%>] = "<%=(oDynaListRS.Fields.Item(txtDynaListValue).Value)%>"
<%
If (len(oDynaListRS.Fields.Item(txtDynaListLabel).Value) > len(varMaxWidth)) Then
varMaxWidth = oDynaListRS.Fields.Item(txtDynaListLabel).Value
End If
varCheckLength = varCheckLength + 1
varDynaList = varDynaList + 3
oDynaListRS.MoveNext()
Wend
If (varCheckLength > varMaxLength) Then
varMaxLength = varCheckLength
End If
%>
//-->
</script>
<!-- End of object/array definitions, beginning of generic functions -->
<script language="JavaScript">
<!--
function setDynaList(arrDL){
var oList1 = document.forms[arrDL[2]].elements[arrDL[1]];
var oList2 = document.forms[arrDL[4]].elements[arrDL[3]];
var arrList = arrDL[5];
clearDynaList(oList2);
if (oList1.selectedIndex == -1){
oList1.selectedIndex = 0;
}
populateDynaList(oList2, oList1[oList1.selectedIndex].value, arrList);
return true;
}
function clearDynaList(oList){
for (var i = oList.options.length; i >= 0; i--){
oList.options[i] = null;
}
oList.selectedIndex = -1;
}
function populateDynaList(oList, nIndex, aArray){
oList[oList.length]= new Option("Please Select");
for (var i = 0; i < aArray.length; i= i + 3){
if (aArray[i] == nIndex){
oList.options[oList.options.length] = new Option(aArray[i + 1], aArray[i + 2]);
}
}
if (oList.options.length == 1){
oList.options[oList.options.length] = new Option(":: No SubCategories Available ::");
}
oList.selectedIndex = 0;
}
//-->
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000" onLoad="setDynaList(arrDL1)">
<p> </p>
<form name="form1" method="post" action="">
<table width="650" border="0" cellspacing="0" cellpadding="5" align="center">
<tr>
<td align="center"> <select name="select1" onChange="setDynaList(arrDL1)" >
<%
While (NOT rsMain.EOF)
%>
<option <%if Request("id")<>"" then%><%=getselectedval(rsMain.Fields.Item("id").Value,rs(1))%><%end if%> value="<%=(rsMain.Fields.Item("id").Value)%>"><%=(rsMain.Fields.Item("title").Value)%></option>
<%
rsMain.MoveNext()
Wend
If (rsMain.CursorType > 0) Then
rsMain.MoveFirst
Else
rsMain.Requery
End If
%>
</select> </td>
<td align="center">
<select name="select2" >
<%if Request("id")<>"" then
While (NOT rssub.EOF)
%>
<option <%=getselectedval(rssub.Fields.Item("id").Value,rs(2))%>></option>
<%
rssub.MoveNext()
Wend
If (rssub.CursorType > 0) Then
rssub.MoveFirst
Else
rssub.Requery
End If
%>
<%end if%>
</select>
</td>
</tr>
<tr>
</table>
</form>
<p> </p>
<p> </p>
</body>
</html>
<%
rsMain.Close()
Set rsMain = Nothing
%>
<%
rsSub.Close()
Set rsSub = Nothing
%>