dropdown for product and sub product
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.......
subrata_ushasi
Junior Poster
105 posts since Aug 2008
Reputation Points: 10
Solved Threads: 6
Skill Endorsements: 0
for two dropdownlist u have to use ajax on the onchange event of first dropdownlist.
manu555
Light Poster
25 posts since Jan 2011
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0
Karthik_pranas
Posting Pro
571 posts since Feb 2011
Reputation Points: 96
Solved Threads: 101
Skill Endorsements: 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>
subrata_ushasi
Junior Poster
105 posts since Aug 2008
Reputation Points: 10
Solved Threads: 6
Skill Endorsements: 0
Replace
<?= $country?>
with
<? echo $country;?>
Karthik_pranas
Posting Pro
571 posts since Feb 2011
Reputation Points: 96
Solved Threads: 101
Skill Endorsements: 0
Hi karthik,
thanks done.
thanks again
subrata_ushasi
Junior Poster
105 posts since Aug 2008
Reputation Points: 10
Solved Threads: 6
Skill Endorsements: 0
Question Answered as of 1 Year Ago by
Karthik_pranas
and
manu555