I have three HTML DropDownList
( <select><option></option></select>
). The first DropDownList
contains categories, the second contains subcategories of different products, and the third contains brands (or manufacturers).
If a category is selected, two subcategories and a drop-down list brand must be populated immediately from the database in accordance with the category identifier passed to the Ajax function. I am using the following Ajax code.
function ajax() { if(window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { xmlhttp = new ActivexObject("Microsoft.XMLHTTP"); } } function getBrandList(selected) //selected is the category id. { ajax(); xmlhttp.onreadystatechange=function() { if(xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("brandList").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","ajax/BrandAjax.php?selected="+selected, true); xmlhttp.send(); alert(selected); } function getSubcategoryList(selected) //selected is the category id. { getBrandList(selected);
When a category is selected, the getSubcategoryList(selected)
Javascript function is getSubcategoryList(selected)
, which executes the Ajax request. The problem is that I need to immediately fill out both the subcategory and the brand (when the category is selected).
It works, and both drop-down lists are filled immediately in accordance with the transmitted category identifier (this is a parameter of the selected
functions above).
I unnecessarily use the warning window at the bottom of the getBrandList()
function. When this notification field is commented out, only one folder is filled in, which is a subcategory. Brands remain empty. I no longer need this warning window.
Why is this happening? What is the solution?
source share