1,105,295 Community Members

dropdown for product and sub product

Member Avatar
subrata_ushasi
Junior Poster
115 posts since Aug 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 0 [?]
 
0
 

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.......

Member Avatar
manu555
Light Poster
25 posts since Jan 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
karthik_ppts
Posting Pro
574 posts since Feb 2011
Reputation Points: 81 [?]
Q&As Helped to Solve: 101 [?]
Skill Endorsements: 1 [?]
 
1
 
Member Avatar
subrata_ushasi
Junior Poster
115 posts since Aug 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 0 [?]
 
0
 

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>
Member Avatar
karthik_ppts
Posting Pro
574 posts since Feb 2011
Reputation Points: 81 [?]
Q&As Helped to Solve: 101 [?]
Skill Endorsements: 1 [?]
 
0
 

Replace

<?= $country?>

with

<? echo $country;?>
Member Avatar
subrata_ushasi
Junior Poster
115 posts since Aug 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi karthik,
thanks done.
thanks again

Question Answered as of 2 Years Ago by karthik_ppts and manu555
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article