Hi!
I'm working on some cool functionality, so that if you click on a "category"
option from the first database-driven selection list, the second select list
loads with keyed "subcategory" options.
Right now, there are two problems that occur just after the form is posted:
1) The page is not recalling the first value selected. For some reason,
the "#if ($selectvalue == $loadlist) ..." section below is always evaluated
to false. I've tried variable :) approaches so far, without success.
2) The page should also be executing Velocity's if ... else code for the
second query and load the subcategory options properly at this point, but it
does not. Instead, the 2nd select box is displayed without ANY options.
Current code:
<script language="JavaScript" type="text/javascript">
<!--
function loadSubcats(theForm) {
var jsloadlist = document.getElementById("selcat").value;
var actiongoto = "../apps/dblcattest?catkey=" + jsloadlist;
document.location = actiongoto;
return (document.location);
theForm.submit();
}
//-->
</script>
<form method="POST" onSubmit="document.location=loadSubcats(this);
return
false">
<%
loadlist = request.getParameter("catkey");
if (!loadlist) {loadlist = "null" };
%>
1 Dependent Category Selection Test
<select id="selcat" name="selcat"
onchange="loadSubcats()">
#set ($hqlcat = ", BaseObject as obj where obj.name=doc.fullName and
obj.className='Doc.NavCatClass' and obj.name not like '%ClassTemplate'
order
by doc.fullName")
#foreach ($item in $xwiki.searchDocuments($hqlcat))
#set ($optcat = $xwiki.getDocument($item))
#set ($selectvalue = $optcat.name)
#if ($selectvalue == $loadlist)
#set ($recall = "selected")
#else
#set ($recall = "")
#end
<option value="$selectvalue" $recall>${optcat.title}</option>
#end
</select>
<br>
<select id="selsubcat" name="selsubcat">
#if (${loadlist} == "null")
{
<option value="error">--</option>
}
#else {
#set ($hqlsubcat = ", BaseObject as obj, StringProperty as prop where
obj.name=doc.fullName and obj.className='Doc.NavSubCatClass' and obj.name
not like '%ClassTemplate' and obj.id=prop.id.id and
prop.id.name='parentkey'
and prop.value='${catkey}' order by doc.fullName")
#foreach ($item in $xwiki.searchDocuments($hqlsubcat))
{
#set($optsubcat = $xwiki.getDocument($item))
<option value="${optsubcat.name}">${optsubcat.title}</option>
}
#end
}
#end
</select>
</form>
Any ideas? Many thanks in advance!
Danielle
_________________________________________________________________
Got something to buy, sell or swap? Try Windows Live Expo
ttp://clk.atdmt.com/MSN/go/msnnkwex0010000001msn/direct/01/?href=http://exp…