megala
02-21-2008, 06:42 AM
Hi,
i'm implementing a dynamic dependant drop downlist this to the edit page. And therefore my page should display
by default display the selected value for category and subcategory.
I have managed to display the category by default, but the subcategory still displays as Please select.
I have change the onchange javascript to fire onload of body, yet doesnt help. Can somebody please help me with this.
this is my code. The listbox chnage changes based on the category selection.
<%
imgid =request.querystring("imgID")
session("userID")="1"
%>
<script language="javascript">
function listboxchange(p_index)
{
<%
'SQL Statement which groupes all authors together, to handle more than 1 book per author
mySQL = "SELECT * FROM TBL_ImageCategory cat, TBL_SubImageCategory sub WHERE cat.imgcategoryid=sub.imgcategoryid ORDER BY imgcategoryname ASC, subimgcategoryname ASC"
'Get Recordset using our SQL
Set myRS = Conn.Execute(mySQL)
%>
switch (p_index)
{
<%
'Loop Through all authors and books
Do Until myRS.eof
StartSub = myRS("ImgCategoryID")
Cnt = 0
%>
case "<%=StartSub%>" :
<%
'Loop until we disover a sub category
do until myrs.eof or StartSub <> myRS("ImgCategoryID")
set RSGetPhotoCat=Conn.Execute("sp_GetAllPhotoDetailsByPhotoID'"&session("userID")&"','"&imgid&"'")
If not RSGetPhotoCat.EOF then
if RSGetPhotoCat("subimgcategoryid") = myRs("subimgcategoryid") then
sselected2="true"
else
sselected2="false"
end if
ENd If
%>
document.frm_adddesc.listbox2.options[<%=cnt%>]=new Option("<%=myRs("subimgcategoryname")%>","<%=myRs("subimgcategoryid")%>","");
document.frm_adddesc.listbox2.options[<%=cnt%>].selected=<%=sselected2%>;
<%
Cnt = Cnt + 1
myrs.movenext
if myrs.eof then exit do
Loop
%>
break;
<%
Loop
myRS.close
Set myRS = nothing
%>
}
return true;
}
</script>
<body onload="javascript:listboxchange('1');">
<form name="frm_adddesc" method="post" action="photodetail.asp?pid=<%=imgid %>" >
<%
Set RsSelectDet=Conn.Execute("Select * from TBL_Mediafiles where mediafileid='"&imgid&"'")
If Not RsSelectDet.EOF then
imgfilename=RsSelectDet("FileName")
End If
picPath = Server.MapPath(("member")& "/" & imgfilename)
encodedurl=Server.URLEncode(picPath)
spath1="include/thumbnail_binary.asp?path="& encodedurl&"&ssize=small"
%>
<table border="0" width="300px" >
<tr>
<td colspan="2"><img src="<%=spath1 %>"></td>
</tr>
<tr>
<td colspan="2">
<table width="100%" border="0">
<%
set RsSelectPhotoDet=Conn.Execute("select * from tbl_Mediafiles where mediafileid='"&imgid&"'")
If not RsSelectPhotoDet.eof then
%>
<%
'Make ListBox1
'SQL Statement which selects each database entry for an category just once
'as we don't want the same name twice in our list box
mySQL = "select distinct imgcategoryid,imgcategoryname from TBL_ImageCategory order by imgcategoryname asc"
//Set myConnection = CreateObject("ADODB.Connection")
//Conn.open myConnectString
Set myRS = Conn.Execute(mySQL)
'Make Drop down box Author list
do until myrs.eof
set RSGetPhotoSubCat=Conn.Execute("sp_GetAllPhotoDetailsByPhotoID'"&session("userID")&"','"&imgid&"'")
If not RSGetPhotoSubCat.EOF then
if RSGetPhotoSubCat("imgcategoryid") = myRs("imgcategoryid") then
sselect="selected"
else
sselect=""
end if
ENd If
ListBox1 = ListBox1 & "<option value=""" & myRs("imgcategoryid") & """"& sselect &">" & myRs("imgcategoryname") & "</option>"
//ListBox1 = ListBox1 & "<option value=""" & myRs("imgcategoryid") & """>" & myRs("imgcategoryname") & "</option>"
myRs.movenext
loop
myRS.close
Set myRS = nothing
//myConnection.close
//Set myConnection = nothing
%>
<tr>
<td><span class="content_txt">Category:</span></td>
<td>
<select name="listbox1" id="listbox1" class="content_txt" runat="server" onchange="javascript: listboxchange(this.options[this.selectedIndex].value);">
<option value="">Please Select</option>
<%=ListBox1%>
</select><br>
<div id ="errcat" style ="display :none" class="errmsg" >*Please select category</div>
<!-- <div id ="errcat2" style ="display :none" class="errmsg" >*Please select sub category</div>-->
</td>
</tr>
<tr>
<td><span class="content_txt">Sub Category:</span></td>
<td>
<select name="listbox2" id="listbox2" class="content_txt">
<option value="">Please Select</option>
</select><br>
<div id ="errcat2" style ="display :none" class="errmsg" >*Please select sub category</div>
</td>
</tr>
<%end if %>
</table>
</td>
</tr>
</table>
</form>
i'm implementing a dynamic dependant drop downlist this to the edit page. And therefore my page should display
by default display the selected value for category and subcategory.
I have managed to display the category by default, but the subcategory still displays as Please select.
I have change the onchange javascript to fire onload of body, yet doesnt help. Can somebody please help me with this.
this is my code. The listbox chnage changes based on the category selection.
<%
imgid =request.querystring("imgID")
session("userID")="1"
%>
<script language="javascript">
function listboxchange(p_index)
{
<%
'SQL Statement which groupes all authors together, to handle more than 1 book per author
mySQL = "SELECT * FROM TBL_ImageCategory cat, TBL_SubImageCategory sub WHERE cat.imgcategoryid=sub.imgcategoryid ORDER BY imgcategoryname ASC, subimgcategoryname ASC"
'Get Recordset using our SQL
Set myRS = Conn.Execute(mySQL)
%>
switch (p_index)
{
<%
'Loop Through all authors and books
Do Until myRS.eof
StartSub = myRS("ImgCategoryID")
Cnt = 0
%>
case "<%=StartSub%>" :
<%
'Loop until we disover a sub category
do until myrs.eof or StartSub <> myRS("ImgCategoryID")
set RSGetPhotoCat=Conn.Execute("sp_GetAllPhotoDetailsByPhotoID'"&session("userID")&"','"&imgid&"'")
If not RSGetPhotoCat.EOF then
if RSGetPhotoCat("subimgcategoryid") = myRs("subimgcategoryid") then
sselected2="true"
else
sselected2="false"
end if
ENd If
%>
document.frm_adddesc.listbox2.options[<%=cnt%>]=new Option("<%=myRs("subimgcategoryname")%>","<%=myRs("subimgcategoryid")%>","");
document.frm_adddesc.listbox2.options[<%=cnt%>].selected=<%=sselected2%>;
<%
Cnt = Cnt + 1
myrs.movenext
if myrs.eof then exit do
Loop
%>
break;
<%
Loop
myRS.close
Set myRS = nothing
%>
}
return true;
}
</script>
<body onload="javascript:listboxchange('1');">
<form name="frm_adddesc" method="post" action="photodetail.asp?pid=<%=imgid %>" >
<%
Set RsSelectDet=Conn.Execute("Select * from TBL_Mediafiles where mediafileid='"&imgid&"'")
If Not RsSelectDet.EOF then
imgfilename=RsSelectDet("FileName")
End If
picPath = Server.MapPath(("member")& "/" & imgfilename)
encodedurl=Server.URLEncode(picPath)
spath1="include/thumbnail_binary.asp?path="& encodedurl&"&ssize=small"
%>
<table border="0" width="300px" >
<tr>
<td colspan="2"><img src="<%=spath1 %>"></td>
</tr>
<tr>
<td colspan="2">
<table width="100%" border="0">
<%
set RsSelectPhotoDet=Conn.Execute("select * from tbl_Mediafiles where mediafileid='"&imgid&"'")
If not RsSelectPhotoDet.eof then
%>
<%
'Make ListBox1
'SQL Statement which selects each database entry for an category just once
'as we don't want the same name twice in our list box
mySQL = "select distinct imgcategoryid,imgcategoryname from TBL_ImageCategory order by imgcategoryname asc"
//Set myConnection = CreateObject("ADODB.Connection")
//Conn.open myConnectString
Set myRS = Conn.Execute(mySQL)
'Make Drop down box Author list
do until myrs.eof
set RSGetPhotoSubCat=Conn.Execute("sp_GetAllPhotoDetailsByPhotoID'"&session("userID")&"','"&imgid&"'")
If not RSGetPhotoSubCat.EOF then
if RSGetPhotoSubCat("imgcategoryid") = myRs("imgcategoryid") then
sselect="selected"
else
sselect=""
end if
ENd If
ListBox1 = ListBox1 & "<option value=""" & myRs("imgcategoryid") & """"& sselect &">" & myRs("imgcategoryname") & "</option>"
//ListBox1 = ListBox1 & "<option value=""" & myRs("imgcategoryid") & """>" & myRs("imgcategoryname") & "</option>"
myRs.movenext
loop
myRS.close
Set myRS = nothing
//myConnection.close
//Set myConnection = nothing
%>
<tr>
<td><span class="content_txt">Category:</span></td>
<td>
<select name="listbox1" id="listbox1" class="content_txt" runat="server" onchange="javascript: listboxchange(this.options[this.selectedIndex].value);">
<option value="">Please Select</option>
<%=ListBox1%>
</select><br>
<div id ="errcat" style ="display :none" class="errmsg" >*Please select category</div>
<!-- <div id ="errcat2" style ="display :none" class="errmsg" >*Please select sub category</div>-->
</td>
</tr>
<tr>
<td><span class="content_txt">Sub Category:</span></td>
<td>
<select name="listbox2" id="listbox2" class="content_txt">
<option value="">Please Select</option>
</select><br>
<div id ="errcat2" style ="display :none" class="errmsg" >*Please select sub category</div>
</td>
</tr>
<%end if %>
</table>
</td>
</tr>
</table>
</form>