Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New to the CF scene
    Join Date
    Jun 2008
    Thanked 0 Times in 0 Posts

    Unhappy how do i get subcategories by selecting categories in select option by javascript

    i have two select boxes..
    one for main category and another for the subcategory.
    when i select any category from main category select box , it calls the javascript function and brings the subcategories of the selected main categroy.
    i am having problem in generating subcategories by javascript.
    i can generate it by php code but my requirement is to generate it by javascript. any solution guys..
    here is the example what am i asking
    <script language="javascript">
    function updatecategory(selectObj){
     var idx = selectObj.selectedIndex; 
     var which = selectObj.options[idx].value;
    var cLists=categoryLists(which);
    function categoryLists(catid) {
    alert(dont know what to do here in this function);
    return catid ;
    <form name="RTEDemo" id="RTEDemo" method="post" >
    <select name="maincategory" id="maincategory" onChange="updatecategory(this);">
    		<option value=" ">-------</option>
    		<? $tq="SELECT * FROM `categories` ORDER BY `name` ASC  ";
    		$rtq=mysql_query($tq) or die("Erorr in $tq".mysql_error($rtq));
    		while ($op=mysql_fetch_array($rtq))
    		echo "<option value='$op[0]'>$op[1]</option>";
    <select name="subcategory" id="subcategory" ><option value="0">-------</option>
    	  $qo="select * from `subcategory` where `categoryname`='$nam[1]'";
    	  	$qoe=mysql_query($qo) or die("error$qo".mysql_error()); 
    		 $qo="select * from `subcategory` where `categoryid`='$scat'";
    	  	$qoe=mysql_query($qo) or die("error$qo".mysql_error()); 
    		while($subcat=mysql_fetch_array($qoe)) {
    		echo "<option value=\"$subcat[0]\">$subcat[3]</option>";
    		}//end while ?>
    please help me. im new in javascripting.
    Last edited by n-jay; 06-09-2008 at 08:34 AM. Reason: edited my code


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts