OK🙂🙂
Here is my HTML code.
<tr><td class="formLabelAlign"><strong>Select Category:</strong> </td><td align="left">{CATEGORY}</td></tr>
<tr><td class="formLabelAlign"><strong>Select Subcategory:</strong> </td><td align="left"><span id = "divSubCategory">{SUBCATEGORY}</span></td></tr>
Here is the combo which I have generated in PHP and passed it in HTML form.
Generating category combo....
$select = '';
$select .='<select name="category" onchange="getSubCategory();" id="category" class="selectInput2">';
$select .= "<option value='0'></option>";
$sql = "select * from tbl_category where parentId = 0 order by categoryId";
$result = $db->EXECUTE($sql);
if ($result == false) die("lib.php --> Getting category name");
while(!$result->EOF)
{
if($result->fields['categoryId'] == $selected)
{
$select .= '<option value = "'.$result->fields['categoryId'].'" selected >'.$result->fields['category'].'</option>';
}
else
{
$select .= '<option value = "'.$result->fields['categoryId'].'">'.$result->fields['category'].'</option>';
}
$result->MoveNext();
}
$select .='</select>';
Generating subcategory combo and echoing for ajax result.....
$subCombo = "<select name='subCategory' class='customCombo'>";
$subCombo .= "<option value='0'></option>";
if($categoryId != 0)
{
$sqlCategory = 'select * from tbl_category where parentId='.$categoryId.' order by category';
$resCategory = $db->EXECUTE($sqlCategory);
if($resCategory == false) die("Data base connection fail: Select SubCategory");
if($resCategory->RecordCount() >0)
{
while(!$resCategory->EOF)
{
$subCombo .= "<option value='".$resCategory->fields['categoryId']."'>".$resCategory->fields['category']."</option>";
$resCategory->MoveNext();
}
}
}
$subCombo .= "</select>";
echo $subCombo;
js function that is called on change event of category combo,
function getSubCategory()
{
categoryId=document.frm1.category.value;
getSubCategoryAjax('intermediate.php?mode=category&cid='+categoryId+'&cmbClass=selectInput','divSubCategory');
}
and finally here is the ajax code...
function callAJAX(url, pageElement, callMessage)
{
document.getElementById(pageElement).innerHTML = callMessage;
try
{
req = new XMLHttpRequest(); /* e.g. Firefox */
}
catch(e)
{
try
{
req = new ActiveXObject("Msxml2.XMLHTTP");
/* some versions IE */
}
catch (e)
{
try
{
req = new ActiveXObject("Microsoft.XMLHTTP");
/* some versions IE */
}
catch (E)
{
req = false;
}
}
}
req.onreadystatechange = function() {responseAJAX(pageElement);};
req.open("GET",url,true);
req.send(null);
}
function responseAJAX(pageElement)
{
var output = '';
if(req.readyState == 4)
{
if(req.status == 200)
{
output = req.responseText;
document.getElementById(pageElement).innerHTML = output;
}
}
}
function getSubCategoryAjax(url, pageElement, callMessage)
{
callAJAX(url, pageElement, callMessage);
}
🙂. I am not able to find what is the exact problem behind this... Please help me friends. Thanks in advnace.