Hey all,
I have a category dropdown list, which takes the category from the database.
now when a user select a category, it should display all the subcategory belong to the subcategory... now user can select more than one subcategory. thats why i had take array of subcategory, now can any one please tell me how do u pass the take this array value to the javascript. as i have to store more than one subcategory to the DB. i have to take an array of the subcategory.
please please help me .. here is my code please tell where am i wrong.
<script language="javascript">
function subdivchk()
{
ClearOptions(document.reg.subcategory);
var a = document.reg.category1.value;
<?php
$sql = mysql_query("select distinct Cat_Grp FROM rms_category");
while($res=mysql_fetch_assoc($sql))
{
$cname=$res['Cat_Grp'];
?>
if (a=='<?php echo $cname ?>')
{
<?php
$subsql=mysql_query("select * from rms_category where Cat_Grp='$cname'");
while($subres=mysql_fetch_assoc($subsql))
{
$scn=$subres['Name'];
$scname=$subres['MetaText'];
?>
AddToOptionList(document.reg.subcategory,"<?php print $scname; ?>","<?php print $scname; ?>", false );
<?php
}
?>
}
<?php
}
?>
}
function ClearOptions(OptionList)
{
for (x = OptionList.length; x >= 0; x = x - 1)
{
OptionList[x] = null;
}
}
function AddToOptionList(OptionList, OptionValue, OptionText,defSel)
{
OptionList[OptionList.length] = new Option(OptionText, OptionValue,"",defSel);
}
</script>
<?php
$res = mysql_query("SELECT distinct(Cat_Grp) FROM rms_category ORDER BY Cat_Grp") or die(mysql_error());
$category = "<select name=category1 OnChange='javascript:subdivchk()'>";
while ($row = mysql_fetch_assoc($res)){
$cntval = $row['Cat_Grp'];
$category .= "<option value='$cntval'> $cntval </option>";
}
$category .= "</select>";
$t->set_var("category_listing",$category);
//////////CODE FOR SUBCATEGORY
//$cntval = "";
//$res = mysql_query("SELECT * FROM rms_category where Cat_Grp='$cntval' ORDER BY Cat_Grp") or die(mysql_error());
$res = mysql_query("SELECT * FROM rms_category ORDER BY Cat_Grp") or die(mysql_error());
$subcategory = "<select name=subcategory[] multiple>";
while ($row = mysql_fetch_assoc($res)){
$subcategory .= "<option value=$row[MetaText] {".$row["Name"]."}> $row[MetaText] </option>";
}
$subcategory .= "</select>";
$t->set_var("sub_category_listing",$subcategory);
please please help me i m so much confused, how to do this???