lordphate Posted March 13, 2009 Share Posted March 13, 2009 Hey Guys, this also includes a bit of PHP, but i'm having issues with the javascript part: function module_categories(){ admin_validate(); $theme = $GLOBALS["Get"]->val("theme"); if(empty($theme)) $theme = $GLOBALS["THEME"]; $data["theme"] = $theme; $data["title_id"] = "38"; $data["module"] = $module; $data["modules"] = admin_get_modules(); $data["link"] = "index.php?section=cars_categories&theme=".$data["theme"]; $data["section"] = "setup"; $data["subsection"] = 4; include(DOC_ROOT."/themes/".$data["theme"]."/system/cars.inc.php"); $jscode = ""; while(list($key,$val) = each($categories)){ $jscode.= "HS_Categories[".$key."] = \"".hs_ereg_replace('"','\"',$val)."\";\n"; }//while while(list($key,$val) = each($subcategories)){ $jscode.= "HS_SubCategories[".$key."] = new Array;\n"; while(list($k,$v) = each($val)){ $jscode.= "HS_SubCategories[".$key."][".$k."] = \"".hs_ereg_replace('"','\"',$v)."\";\n"; }//while }//while while(list($key2,$val2) = each($subsubcategories)){ $jscode.= "HS_SubSubCategories[".$key2."] = new Array;\n"; while(list($k2,$v2) = each($val2)){ $jscode .= "HS_SubSubCategories[".$key2."][".$k2."] = new Array;\n"; while(list($k3,$v3) = each($v2)){ $jscode.= "HS_SubSubCategories[".$key2."][".$k2."][".$k3."] = \"".hs_ereg_replace('"','\"',$v3)."\";\n"; } }//while }//while $data["javascript"] = <<<JAVASCRIPTCODE <script language="JavaScript"> <!-- var HS_Categories = new Array; var HS_SubCategories = new Array; var HS_SubSubCategories = new Array; var Category = 0; var SubCategory = 0; var SubSubCategory = 0; function HS_InitCategories(){ $jscode }//HS_InitCategories function HS_PopulateSubCategoriesSimple(){ var FormHandler = document.classifieds_search; Category = FormHandler.category.options[FormHandler.category.selectedIndex].value; for(var i=FormHandler.subcategory.options.length-1; i>=0; i--){ FormHandler.subcategory.options[i] = null; }//for FormHandler.subcategory.options[0] = new Option("Please, select...","0"); var k=1; for(var Item in HS_SubCategories[Category]){ FormHandler.subcategory.options[k] = new Option(HS_SubCategories[Category][item],Item); k++; }//for }//HS_PopulateSubCategoriesSimple function HS_PopulateSubCategories(){ var FormHandler = document.cls_categories; Category = FormHandler.categories.options[FormHandler.categories.selectedIndex].value; for(var i=FormHandler.subcategories.options.length-1; i>=0; i--){ FormHandler.subcategories.options[i] = null; }//for var k=0; for(var Item in HS_SubCategories[Category]){ if(HS_SubCategories[Category][item] != "EMPTY"){ FormHandler.subcategories.options[k] = new Option(HS_SubCategories[Category][item],Item); k++; }//if }//for FormHandler.edit_category.value = HS_Categories[Category]; FormHandler.edit_subcategory.value = ""; HS_SubCategory = 0; }//HS_PopulateSubCategories function HS_EditSubCategory(){ if(Category){ var FormHandler = document.cls_categories; SubCategory = FormHandler.subcategories.options[FormHandler.subcategories.selectedIndex].value; FormHandler.edit_subcategory.value = HS_SubCategories[Category][subCategory]; }//if }//HS_EditSubCategory function HS_PopulateSubSubCategoriesSimple(){ var FormHandler = document.classifieds_search; Category = FormHandler.category.options[FormHandler.category.selectedIndex].value; SubCategory = FormHandler.subcategory.options[FormHandler.subcategory.selectedIndex].value; for(var i=FormHandler.subsubcategory.options.length-1; i>=0; i--){ FormHandler.subsubcategory.options[i] = null; }//for FormHandler.subsubcategory.options[0] = new Option("Please, select...","0"); var k=1; for(var Item in HS_SubSubCategories[Category][subCategory]){ FormHandler.subsubcategory.options[k] = new Option(HS_SubSubCategories[Category][subCategory][item],Item); k++; }//for }//HS_PopulateSubSubCategoriesSimple function HS_PopulateSubSubCategories(){ var FormHandler = document.cls_categories; Category = FormHandler.categories.options[FormHandler.categories.selectedIndex].value; SubCategory = FormHandler.subcategories.options[FormHandler.subcategories.selectedIndex].value; for(var i=FormHandler.subsubcategories.options.length-1; i>=0; i--){ FormHandler.subsubcategories.options[i] = null; }//for var k=0; for(var Item in HS_SubSubCategories[Category][subCategory]){ if(HS_SubSubCategories[Category][subCategory][item] != "EMPTY"){ FormHandler.subsubcategories.options[k] = new Option(HS_SubSubCategories[Category][subCategory][item],Item); k++; }//if }//for FormHandler.edit_category.value = HS_Categories[Category]; FormHandler.edit_subcategory.value = HS_SubCategories[Category][subCategory]; FormHandler.edit_subsubcategory.value = ""; HS_SubSubCategory = 0; }//HS_PopulateSubSubCategories function HS_EditSubSubCategory(){ if(SubCategory){ var FormHandler = document.cls_categories; SubSubCategory = FormHandler.subsubcategories.options[FormHandler.subsubcategories.selectedIndex].value; FormHandler.edit_subsubcategory.value = HS_SubSubCategories[Category][subCategory][subSubCategory]; }//if }//HS_EditSubCategory function HS_AddCategory(){ var FormHandler = document.cls_categories; var CategoryName = FormHandler.new_category.value; var CatID = HS_Categories.length+1; HS_Categories[CatID] = CategoryName; HS_SubCategories[CatID] = new Array; FormHandler.categories.options[FormHandler.categories.options.length] = new Option(CategoryName,CatID); FormHandler.new_category.value = ""; }//HS_AddCategory function HS_AddSubCategory(){ if(Category){ var FormHandler = document.cls_categories; var SubCategoryName = FormHandler.new_subcategory.value; var SubCatID = HS_SubCategories[Category].length+1; HS_SubCategories[Category][subCatID] = SubCategoryName; FormHandler.subcategories.options[FormHandler.subcategories.options.length] = new Option(SubCategoryName,SubCatID); FormHandler.new_subcategory.value = ""; }//if }//HS_AddSubCategory function HS_AddSubSubCategory(){ if(SubCategory){ var FormHandler = document.cls_categories; var SubSubCategoryName = FormHandler.new_subsubcategory.value; var SubSubCatID = HS_SubSubCategories[Category][subCategory].length+1; HS_SubSubCategories[Category][subCategory][subSubCatID] = SubSubCategoryName; FormHandler.subsubcategories.options[FormHandler.subsubcategories.options.length] = new Option(SubSubCategoryName,SubSubCatID); FormHandler.new_subsubcategory.value = ""; }//if }//HS_AddSubCategory function HS_UpdateCategory(){ if(Category){ var FormHandler = document.cls_categories; var CategoryName = FormHandler.edit_category.value; HS_Categories[Category] = CategoryName; var Selected = FormHandler.categories.selectedIndex; FormHandler.categories.options[selected] = new Option(CategoryName,Category); FormHandler.categories.selectedIndex = Selected; }//if }//HS_UpdateCategory function HS_UpdateSubCategory(){ if(Category && SubCategory){ var FormHandler = document.cls_categories; var SubCategoryName = FormHandler.edit_subcategory.value; HS_SubCategories[Category][subCategory] = SubCategoryName; var Selected = FormHandler.subcategories.selectedIndex; FormHandler.subcategories.options[selected] = new Option(SubCategoryName,SubCategory); FormHandler.subcategories.selectedIndex = Selected; }//if }//HS_UpdateSubCategory function HS_UpdateSubSubCategory(){ if(Category && SubCategory && SubSubCategory){ var FormHandler = document.cls_categories; var SubSubCategoryName = FormHandler.edit_subsubcategory.value; HS_SubSubCategories[Category][subCategory][subSubCategory] = SubSubCategoryName; var Selected = FormHandler.subsubcategories.selectedIndex; FormHandler.subsubcategories.options[selected] = new Option(SubSubCategoryName,SubSubCategory); FormHandler.subsubcategories.selectedIndex = Selected; }//if }//HS_UpdateSubCategory function HS_DeleteCategory(){ if(Category){ var FormHandler = document.cls_categories; HS_Categories[Category] = "EMPTY"; FormHandler.categories.options[FormHandler.categories.selectedIndex] = null; FormHandler.edit_category.value = ""; FormHandler.edit_subcategory.value = ""; Category = 0; SubCategory = 0; for(var i=FormHandler.subcategories.options.length; i>=0; i--){ FormHandler.subcategories.options[i] = null; }//for }//if }//HS_DeleteCategory function HS_DeleteSubCategory(){ if(Category && SubCategory){ var FormHandler = document.cls_categories; HS_SubCategories[Category][subCategory] = "EMPTY"; FormHandler.subcategories.options[FormHandler.subcategories.selectedIndex] = null; FormHandler.edit_subcategory.value = ""; SubCategory = 0; }//if }//HS_DeleteSubCategory function HS_DeleteSubSubCategory(){ if(Category && SubCategory && SubSubCategory){ var FormHandler = document.cls_categories; HS_SubSubCategories[Category][subCategory][subSubCategory] = "EMPTY"; FormHandler.subsubcategories.options[FormHandler.subsubcategories.selectedIndex] = null; FormHandler.edit_subsubcategory.value = ""; SubSubCategory = 0; }//if }//HS_DeleteSubCategory function HS_UpdateData(){ var CatsLine = ""; var SubCatsLine = ""; var SubSubCatsLine = ""; var TotalCats = 0; var Rules = new Array(); var Error = 0; var FormHandler = document.cls_categories; for(var Item in HS_Categories){ if(HS_Categories[item] != "EMPTY"){ CatsLine+= Item+"|"+HS_Categories[item]+"==|=="; Rules[item] = 0; TotalCats++; for(var SubItem in HS_SubCategories[item]){ SubCatsLine+= Item+"|"+SubItem+"|"+HS_SubCategories[item][subItem]+"==|=="; if(HS_SubCategories[item][subItem] != "EMPTY") Rules[item] = 0; }//for for(var SubSubItem in HS_SubSubCategories[item][subItem]){ SubSubCatsLine+= Item+"|"+SubItem+"|"+SubSubItem+"|"+HS_SubSubCategories[item][subItem][subSubItem]+"==|=="; if(HS_SubSubCategories[subItem][subSubItem] != "EMPTY") Rules[subItem] = 0; }//for }//if else{ for(var SubItem in HS_SubCategories[item]){ SubCatsLine+= Item+"|"+SubItem+"|EMPTY==|=="; }//for for(var SubSubItem in HS_SubSubCategories[item]){ SubSubCatsLine+= Item+"|"+SubSubItem+"|EMPTY==|=="; }//for }//else }//for for(var Rule in Rules){ if(Rules[Rule] == 0){ Error = 1; }//if }//for if(TotalCats == 0) Error = 2; FormHandler.res_categories.value = CatsLine; FormHandler.res_subcategories.value = SubCatsLine; FormHandler.res_subsubcategories.value = SubSubCatsLine; FormHandler.submit(); }//HS_UpdateData //--> </script> JAVASCRIPTCODE; $data["onload"] = "HS_InitCategories();"; $data["categories"] = $categories; $data["subcategories"] = $subcategories; $data["subsubcategories"] = $subsubcategories; $layout[0] = "cars_categories"; admin_output($layout,$data); }//module_categories the error i'm getting is: Error: HS_SubSubCategories[item] is undefined at this area for(var SubSubItem in HS_SubSubCategories[item][subItem]){ SubSubCatsLine+= Item+"|"+SubItem+"|"+SubSubItem+"|"+HS_SubSubCategories[item][subItem][subSubItem]+"==|=="; if(HS_SubSubCategories[subItem][subSubItem] != "EMPTY") Rules[subItem] = 0; }//for Any one have any clue Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted March 13, 2009 Share Posted March 13, 2009 for(var SubSubItem in HS_SubSubCategories[item][subItem]){ SubSubCatsLine+= Item+"|"+SubItem+"|"+SubSubItem+"|"+HS_SubSubCategories[item][subItem][subSubItem]+"==|=="; if(HS_SubSubCategories[subItem][subSubItem] != "EMPTY"){ Rules[subItem] = 0;} }//for also Problem at line 1 character 6: The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype. Quote Link to comment Share on other sites More sharing options...
lordphate Posted March 13, 2009 Author Share Posted March 13, 2009 for(var SubSubItem in HS_SubSubCategories[item][subItem]){ SubSubCatsLine+= Item+"|"+SubItem+"|"+SubSubItem+"|"+HS_SubSubCategories[item][subItem][subSubItem]+"==|=="; if(HS_SubSubCategories[subItem][subSubItem] != "EMPTY"){ Rules[subItem] = 0;} }//for also Problem at line 1 character 6: The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype. Umm truthfully i have NO idea what you mean...i'm such a n00b at javascript Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted March 14, 2009 Share Posted March 14, 2009 for in The for in statement allows for looping through the names of all of the properties of an object. Unfortunately, it also loops through all of the members which were inherited through the prototype chain. This has the bad side effect of serving up method functions when the interest is in data members. The body of every for in statement should be wrapped in an if statement that does filtering. It can select for a particular type or range of values, or it can exclude functions, or it can exclude properties from the prototype. For example, for (name in object) { if (object.hasOwnProperty(name)) { .... } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.