Hi all,
I am creating an cms/admin where I want a drop down consists of list of product and an another drop down consists of list of sub products. On selection a product ,the corresponding lists of sub product will be generated in sub product drop down. using javascript I did

if(empty($_POST["productid"]))
   {
   $product_id=!empty($_REQUEST['pid']);
   echo $product_id;
  
   }
else
   {
   $product_id=$_POST['productid'];
   /*THIS PART IS NOT WORKING */
   }

<SCRIPT LANGUAGE="javascript">
function update_post()
{
 document.frm.submit();
}
</SCRIPT>

 <select id="productid" name="productid" onChange="update_post();">
	<?php 
           $sql_all ="select * from product";
	   $qry_selectall=mysql_query($sql_all);
	   while($res_selectall=mysql_fetch_array($qry_selectall))
	     {
             $content_all=$res_selectall['id'];
	     $code = $res_selectall['page_title'];
	 ?>
<option id="prodid" value="<?php echo $content_all;?>" <?php if($content_all==$page_id) echo 'selected' ?> ><?php echo $code;?></option>
  	<?php
            }
	    ?>
	  </select>

where the else part is not working. If any one can post a full code for two drop down using php ,html and javascript.......

Recommended Answers

All 5 Replies

for two dropdownlist u have to use ajax on the onchange event of first dropdownlist.

Hi Karthik ,

<?php 
$country=intval($_GET['country']);
mysql_select_db('test');
$query="SELECT id,statename FROM state WHERE countryid=$country";
$result=mysql_query($query);  // till here is ok 
?>
Your code is :
<select name="state" onchange="getCity(<?= $country?>,this.value)">
<option>Select State</option>
<? while($row=mysql_fetch_array($result)) { ?>
<option value=<?= $row['id']?>><?= $row['statename']?></option>
<? } ?>
</select>

but I am working in wampserver which supports <php ?> not <??> so
<option value=<?[B]=[/B] $row['id']?>><?[B]= [/B]$row['statename']?></option> portion is not working .I changed it as follows :
<select name="state" onchange="getCity(<?php $country?>,this.value)">
<option>Select State</option>
<?php while($row=mysql_fetch_array($result)) { ?>
<option value=<?php $row['id']?>><?php $row['statename']?></option>
<?php } ?>
</select>

Replace

<?= $country?>

with

<? echo $country;?>

Hi karthik,
thanks done.
thanks again

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.