shawntbanks
Programmer
I seem to have no problem populating a second menu from scratch, but when I try to do a edit page for my shopping cart application, I seem to run into problems, and I can't figure out how to do it. When a customer wants to edit their selection I populate the menues from the cart, the category menu works fine execpt there is a duplicate in it, and the duplicate does not have any subcategories execpt for the one that I put in it.
<cfquery name="get_SubCategories" datasource="Market">
SELECT Category, categoryid, subcategory, subcategoryid
FROM subandcat
<cfset idx = -1>
<cfset mycase = 0>
<SCRIPT LANGUAGE="JavaScript">
function whichLocal(obj){
switch (obj.select_Ad_Subcategory.selectedIndex){
<!--- use the group attribute to group output by category --->
<cfoutput query="get_SubCategories" group="Category">
<cfset mycase = mycase + 1>case #mycase#:
<cfset myList = ValueList(get_SubCategories.categoryid)>
<cfset numberInCategory = ListValueCount(myList, categoryid)>
obj.selectLocal.length=#numberInCategory#<cfoutput><cfset idx = idx + 1>
obj.selectLocal.options[#idx#].value="#get_SubCategories.subcategoryid#"
obj.selectLocal.options[#idx#].text="#trim(get_SubCategories.SubCategory)#"</cfoutput>
break;
<cfset idx = -1>
</cfoutput>
}
</script>
<cfquery name="get_Communities" datasource="Market">
SELECT *
FROM Communities
order by location
</cfquery>
<cfquery name="get_SubCategories" datasource="Market">
SELECT Category, categoryid, subcategory, subcategoryid
FROM subandcat
</cfquery>
<cfinclude template="../Templates/Header_&_Sidebar_for_Place_Ad_Folder_Subcat_Select.cfm">
<td width="603" rowspan="2" valign="top" bgcolor="#FFFFFF">
<CFIF IsDefined("FORM.edititemnum">
<CFLOCK timeout="30"
throwontimeout="no"
type="exclusive"
scope="session">
<CFSET SESSION.cart[#FORM.edititemnum#].itemname = FORM.itemname>
<CFSET SESSION.cart[#FORM.edititemnum#].categoryid = FORM.select_Ad_Subcategory>
<CFSET SESSION.cart[#FORM.edititemnum#].subcategoryid = FORM.selectLocal>
<CFSET SESSION.cart[#FORM.edititemnum#].location = FORM.Community_List>
<CFSET SESSION.cart[#FORM.edititemnum#].Short_Description = FORM.Short_Description>
<CFSET SESSION.cart[#FORM.edititemnum#].long_description = FORM.long_description>
<CFSET SESSION.cart[#FORM.edititemnum#].itemprice = FORM.itemprice>
<CFSET SESSION.cart[#FORM.edititemnum#].featured = FORM.featured>
<CFSET SESSION.cart[#FORM.edititemnum#].begindate = FORM.begindate>
<CFSET SESSION.cart[#FORM.edititemnum#].enddate = FORM.begindate + FORM.enddate>
</CFLOCK>
<cflocation url="step3.cfm">
<CFELSE>
<CFSET strEditItem = StructNew()>
<CFLOCK timeout="30"
throwontimeout="no"
type="readonly"
scope="session">
<CFSET strEditItem = SESSION.cart[#URL.itemnum#]>
</CFLOCK>
<!---<cfif isdefined ("url.itemnum"></cfif> --->
<cfquery name="get_cat" datasource="Market">
SELECT Category, categoryid, subcategory, subcategoryid
FROM subandcat
where subcategoryid = #SESSION.cart[URL.itemnum].subcategoryid#
</cfquery>
<cfquery name="get_subcat2" datasource="Market">
SELECT Category, categoryid, subcategory, subcategoryid
FROM subandcat
where categoryid = #get_cat.categoryid#
</cfquery>
<cfform action="edit_item.cfm" method="post" enctype="multipart/form-data">
<table align="center" border="0">
<tr>
<td colspan="5" class="FormHeaders"><div align="center"><font size="4" face="Georgia, Times New Roman, Times, serif"><!--- <cfoutput>#categories.Category#</cfoutput> --->
Details</font></div></td>
</tr>
<tr bgcolor="#EDECE0"><td><font face="Georgia, Times New Roman, Times, serif">Category:</font></td>
<td valign="top" colspan="4">
<select name="select_Ad_Subcategory" onchange="whichLocal(this.form)" size="1">
<cfoutput><option value="#get_cat.categoryid#">#get_cat.category#</option></cfoutput>
<cfoutput query="get_SubCategories" group="Category">
<option value="#Categoryid#">#Category#</option>
</cfoutput>
</select></td></tr>
<tr><td><font face="Georgia, Times New Roman, Times, serif">Subcategory:</font></td>
<td colspan="4"> <select name="selectLocal" onChange="whichLocal(this.form)" size="1">
<cfoutput><option value="#get_cat.subcategoryid#">#get_cat.subcategory#</option></cfoutput>
<cfoutput query="get_subcat2"><option value="#subcategory#">#subcategory#</option></cfoutput>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
</select></td>
</tr>
<tr bgcolor="#EDECE0">
<td><font face="Georgia, Times New Roman, Times, serif">Community:</font></td>
<td colspan="4"><font face="Georgia, Times New Roman, Times, serif">
<select name="Community_List">
<option><cfoutput>#strEditItem.location#</cfoutput></option>
<cfoutput query="Get_Communities">
<option value="#location#">#location#</option>
</cfoutput>
</select>
</font></td>
</tr>
<tr>
<td width="109" ><font face="Georgia, Times New Roman, Times, serif">Item
Name:</font></td>
<td colspan="4"> <font face="Georgia, Times New Roman, Times, serif">
<CFinput name="Itemname" type="text" required="no" message="Item Name Required" value="#strEditItem.itemname#">
</font></td>
</tr>
<tr bgcolor="#EDECE0">
<td valign="top" ><font face="Georgia, Times New Roman, Times, serif">Short
Description:</font></td>
<td colspan="4">
<textarea name="Short_description" cols="30" rows="5" wrap="hard" onChange="if (this.value.length > 100) {alert('The Short Description Cannot Be Greater Than 100 Chars.')};"><cfoutput>#strEditItem.short_description#</cfoutput></textarea>
</td>
</tr>
<tr>
<td valign="top" ><font face="Georgia, Times New Roman, Times, serif">Long
Description:</font></td>
<td colspan="4"><textarea name="Long_description" cols="30" rows="5"><cfoutput>#strEditItem.long_description#</cfoutput></textarea>
</td>
</tr>
<tr bgcolor="#EDECE0">
<td><font face="Georgia, Times New Roman, Times, serif">Asking
Price:</font></td>
<td colspan="4"><CFinput name="itemprice" value="#strEditItem.itemprice#" type="text" id="itemprice" required="no" message="Asking Price Required" size="20" maxlength="9">
</td>
</tr>
<tr>
<td valign="top"><font face="Georgia, Times New Roman, Times, serif"><span >Featured
Item</span><font color="#FF0000">*</font></font></td>
<td colspan="4"> <cfif strEditItem.Featured EQ 1><CFinput name="featured" type="radio" id="featured" value="1"checked="yes"> <cfelse><CFinput name="featured" type="radio" id="featured" value="1"></cfif>
<font size="-2" face="Georgia, Times New Roman, Times, serif">Yes</font> </td>
<tr><td> </td><td colspan="4"> <cfif strEditItem.Featured EQ 0><CFinput name="featured" type="radio" id="featured" value="0" checked="yes"> <cfelse><CFinput name="featured" type="radio" id="featured" value="0"></cfif>
<font size="-2" face="Georgia, Times New Roman, Times, serif">No</font> </td></tr>
</tr>
<tr bgcolor="#EDECE0">
<td><font face="Georgia, Times New Roman, Times, serif">Start
Date Of Ad:</font></td>
<td colspan="4"><cfinput name="begindate" type="text" validate="date" value="#strEditItem.begindate#">
</td>
</tr>
<tr>
<td valign="top"><font face="Georgia, Times New Roman, Times, serif">Length
Of Ad:</font></td>
<td><cfif strEditItem.Enddate EQ strEditItem.begindate + 7><CFinput name="Enddate" type="radio" value="7" checked="yes"><cfelse><CFinput name="Enddate" type="radio" value="7"></cfif></td>
<td><font face="Georgia, Times New Roman, Times, serif">7
Days</font></td>
<tr bgcolor="#EDECE0">
<td><font face="Georgia, Times New Roman, Times, serif"> </font></td>
<td><cfif strEditItem.Enddate EQ strEditItem.begindate + 30><CFinput name="Enddate" type="radio" value="30" checked="yes"><cfelse><CFinput name="Enddate" type="radio" value="30"></cfif></td>
<td><font face="Georgia, Times New Roman, Times, serif">30 Days
</font></td>
</tr></table>
<table align="center" border="0">
<tr bgcolor="#FFFFFF">
<td colspan="5"><div align="center"> <CFOUTPUT><input type="hidden" name="edititemnum" value="#URL.itemnum#"></CFOUTPUT>
<input type="submit" value="Continue >>">
</div></td>
</tr>
</table>
</cfform>
</CFIF>
<tr>
<td background="../images/top_space2.gif"><img src="../images/top_space2.gif"></td>
</tr>
</table>
</td></tr>
</table>
</body>
</html>
<cfquery name="get_SubCategories" datasource="Market">
SELECT Category, categoryid, subcategory, subcategoryid
FROM subandcat
<cfset idx = -1>
<cfset mycase = 0>
<SCRIPT LANGUAGE="JavaScript">
function whichLocal(obj){
switch (obj.select_Ad_Subcategory.selectedIndex){
<!--- use the group attribute to group output by category --->
<cfoutput query="get_SubCategories" group="Category">
<cfset mycase = mycase + 1>case #mycase#:
<cfset myList = ValueList(get_SubCategories.categoryid)>
<cfset numberInCategory = ListValueCount(myList, categoryid)>
obj.selectLocal.length=#numberInCategory#<cfoutput><cfset idx = idx + 1>
obj.selectLocal.options[#idx#].value="#get_SubCategories.subcategoryid#"
obj.selectLocal.options[#idx#].text="#trim(get_SubCategories.SubCategory)#"</cfoutput>
break;
<cfset idx = -1>
</cfoutput>
}
</script>
<cfquery name="get_Communities" datasource="Market">
SELECT *
FROM Communities
order by location
</cfquery>
<cfquery name="get_SubCategories" datasource="Market">
SELECT Category, categoryid, subcategory, subcategoryid
FROM subandcat
</cfquery>
<cfinclude template="../Templates/Header_&_Sidebar_for_Place_Ad_Folder_Subcat_Select.cfm">
<td width="603" rowspan="2" valign="top" bgcolor="#FFFFFF">
<CFIF IsDefined("FORM.edititemnum">
<CFLOCK timeout="30"
throwontimeout="no"
type="exclusive"
scope="session">
<CFSET SESSION.cart[#FORM.edititemnum#].itemname = FORM.itemname>
<CFSET SESSION.cart[#FORM.edititemnum#].categoryid = FORM.select_Ad_Subcategory>
<CFSET SESSION.cart[#FORM.edititemnum#].subcategoryid = FORM.selectLocal>
<CFSET SESSION.cart[#FORM.edititemnum#].location = FORM.Community_List>
<CFSET SESSION.cart[#FORM.edititemnum#].Short_Description = FORM.Short_Description>
<CFSET SESSION.cart[#FORM.edititemnum#].long_description = FORM.long_description>
<CFSET SESSION.cart[#FORM.edititemnum#].itemprice = FORM.itemprice>
<CFSET SESSION.cart[#FORM.edititemnum#].featured = FORM.featured>
<CFSET SESSION.cart[#FORM.edititemnum#].begindate = FORM.begindate>
<CFSET SESSION.cart[#FORM.edititemnum#].enddate = FORM.begindate + FORM.enddate>
</CFLOCK>
<cflocation url="step3.cfm">
<CFELSE>
<CFSET strEditItem = StructNew()>
<CFLOCK timeout="30"
throwontimeout="no"
type="readonly"
scope="session">
<CFSET strEditItem = SESSION.cart[#URL.itemnum#]>
</CFLOCK>
<!---<cfif isdefined ("url.itemnum"></cfif> --->
<cfquery name="get_cat" datasource="Market">
SELECT Category, categoryid, subcategory, subcategoryid
FROM subandcat
where subcategoryid = #SESSION.cart[URL.itemnum].subcategoryid#
</cfquery>
<cfquery name="get_subcat2" datasource="Market">
SELECT Category, categoryid, subcategory, subcategoryid
FROM subandcat
where categoryid = #get_cat.categoryid#
</cfquery>
<cfform action="edit_item.cfm" method="post" enctype="multipart/form-data">
<table align="center" border="0">
<tr>
<td colspan="5" class="FormHeaders"><div align="center"><font size="4" face="Georgia, Times New Roman, Times, serif"><!--- <cfoutput>#categories.Category#</cfoutput> --->
Details</font></div></td>
</tr>
<tr bgcolor="#EDECE0"><td><font face="Georgia, Times New Roman, Times, serif">Category:</font></td>
<td valign="top" colspan="4">
<select name="select_Ad_Subcategory" onchange="whichLocal(this.form)" size="1">
<cfoutput><option value="#get_cat.categoryid#">#get_cat.category#</option></cfoutput>
<cfoutput query="get_SubCategories" group="Category">
<option value="#Categoryid#">#Category#</option>
</cfoutput>
</select></td></tr>
<tr><td><font face="Georgia, Times New Roman, Times, serif">Subcategory:</font></td>
<td colspan="4"> <select name="selectLocal" onChange="whichLocal(this.form)" size="1">
<cfoutput><option value="#get_cat.subcategoryid#">#get_cat.subcategory#</option></cfoutput>
<cfoutput query="get_subcat2"><option value="#subcategory#">#subcategory#</option></cfoutput>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
</select></td>
</tr>
<tr bgcolor="#EDECE0">
<td><font face="Georgia, Times New Roman, Times, serif">Community:</font></td>
<td colspan="4"><font face="Georgia, Times New Roman, Times, serif">
<select name="Community_List">
<option><cfoutput>#strEditItem.location#</cfoutput></option>
<cfoutput query="Get_Communities">
<option value="#location#">#location#</option>
</cfoutput>
</select>
</font></td>
</tr>
<tr>
<td width="109" ><font face="Georgia, Times New Roman, Times, serif">Item
Name:</font></td>
<td colspan="4"> <font face="Georgia, Times New Roman, Times, serif">
<CFinput name="Itemname" type="text" required="no" message="Item Name Required" value="#strEditItem.itemname#">
</font></td>
</tr>
<tr bgcolor="#EDECE0">
<td valign="top" ><font face="Georgia, Times New Roman, Times, serif">Short
Description:</font></td>
<td colspan="4">
<textarea name="Short_description" cols="30" rows="5" wrap="hard" onChange="if (this.value.length > 100) {alert('The Short Description Cannot Be Greater Than 100 Chars.')};"><cfoutput>#strEditItem.short_description#</cfoutput></textarea>
</td>
</tr>
<tr>
<td valign="top" ><font face="Georgia, Times New Roman, Times, serif">Long
Description:</font></td>
<td colspan="4"><textarea name="Long_description" cols="30" rows="5"><cfoutput>#strEditItem.long_description#</cfoutput></textarea>
</td>
</tr>
<tr bgcolor="#EDECE0">
<td><font face="Georgia, Times New Roman, Times, serif">Asking
Price:</font></td>
<td colspan="4"><CFinput name="itemprice" value="#strEditItem.itemprice#" type="text" id="itemprice" required="no" message="Asking Price Required" size="20" maxlength="9">
</td>
</tr>
<tr>
<td valign="top"><font face="Georgia, Times New Roman, Times, serif"><span >Featured
Item</span><font color="#FF0000">*</font></font></td>
<td colspan="4"> <cfif strEditItem.Featured EQ 1><CFinput name="featured" type="radio" id="featured" value="1"checked="yes"> <cfelse><CFinput name="featured" type="radio" id="featured" value="1"></cfif>
<font size="-2" face="Georgia, Times New Roman, Times, serif">Yes</font> </td>
<tr><td> </td><td colspan="4"> <cfif strEditItem.Featured EQ 0><CFinput name="featured" type="radio" id="featured" value="0" checked="yes"> <cfelse><CFinput name="featured" type="radio" id="featured" value="0"></cfif>
<font size="-2" face="Georgia, Times New Roman, Times, serif">No</font> </td></tr>
</tr>
<tr bgcolor="#EDECE0">
<td><font face="Georgia, Times New Roman, Times, serif">Start
Date Of Ad:</font></td>
<td colspan="4"><cfinput name="begindate" type="text" validate="date" value="#strEditItem.begindate#">
</td>
</tr>
<tr>
<td valign="top"><font face="Georgia, Times New Roman, Times, serif">Length
Of Ad:</font></td>
<td><cfif strEditItem.Enddate EQ strEditItem.begindate + 7><CFinput name="Enddate" type="radio" value="7" checked="yes"><cfelse><CFinput name="Enddate" type="radio" value="7"></cfif></td>
<td><font face="Georgia, Times New Roman, Times, serif">7
Days</font></td>
<tr bgcolor="#EDECE0">
<td><font face="Georgia, Times New Roman, Times, serif"> </font></td>
<td><cfif strEditItem.Enddate EQ strEditItem.begindate + 30><CFinput name="Enddate" type="radio" value="30" checked="yes"><cfelse><CFinput name="Enddate" type="radio" value="30"></cfif></td>
<td><font face="Georgia, Times New Roman, Times, serif">30 Days
</font></td>
</tr></table>
<table align="center" border="0">
<tr bgcolor="#FFFFFF">
<td colspan="5"><div align="center"> <CFOUTPUT><input type="hidden" name="edititemnum" value="#URL.itemnum#"></CFOUTPUT>
<input type="submit" value="Continue >>">
</div></td>
</tr>
</table>
</cfform>
</CFIF>
<tr>
<td background="../images/top_space2.gif"><img src="../images/top_space2.gif"></td>
</tr>
</table>
</td></tr>
</table>
</body>
</html>