hi,
I have a list box with product names (product table) and a list box with product details (productdetails table).
When I select a product name the form refreshes and populates the product details list box with values for the product selected.
Previously when I selected a product the data from the product table was written to various text fields, and now I want to make it so that when I select a product, it not only refreshes the form and populates the product details list box, but also populate a number of text fields with data from the product table.
The code I have made works fine to populate the product details list box, but it populates the product text fields BEFORE it refreshes the page (can see it for a split second!) and then when the page finishes refreshing the product fields are blank 🙁
function reload(form)
{
var val=prodform.prodid.options[form.prodid.options.selectedIndex].value;
self.location='product_page.php?prodid=' + val ;
showProductName();
}
function showProductName() {
var prodid = document.prodform.prodid.value;
//var val=prodform.prodid.options[prodform.prodid.options.selectedIndex].value;
//var val = document.prodform.prodid.options[document.prodform.prodid.options.selectedIndex].value;
document.prodform.prodcompid.value = prodDetailsArray[prodid]["prodcompid"];
//document.prodform.proddetid.value = prodDetailsArray[prodid]["prodid"];
document.prodform.prodcode.value = prodDetailsArray[prodid]["prodcode"];
document.prodform.prodname.value = prodDetailsArray[prodid]["prodname"];
document.prodform.prodcategory.value = prodDetailsArray[prodid]["prodcategory"];
document.prodform.produnitprice.value = prodDetailsArray[prodid]["produnitprice"];
document.prodform.prodphoto.value = prodDetailsArray[prodid]["prodphoto"];
document.prodform.proddescription.value = prodDetailsArray[prodid]["proddescription"];
}
//window.onload=function() {
//showProductName();
//reload(form);
//showProductSpecName();
//}
</script>
<?php
@$cat=$_GET['prodid']; // Use this line or below line if register_global is off
if(strlen($cat) > 0 and !is_numeric($cat)){ // to check if $cat is numeric data or not.
echo "Data Error";
exit;
}
///////// Getting the data from Mysql table for first list box//////////
$quer2=mysql_query("SELECT DISTINCT prodname,prodid FROM product where userid = '".$_SESSION['userid']."' order by prodname");
///////////// End of query for first list box////////////
/////// for second drop down list we will check if category is selected else we will display all the subcategory/////
if(isset($cat) and strlen($cat) > 0){
$quer=mysql_query("SELECT DISTINCT proddetfield FROM productdetail where prodid=$cat order by proddetfield");
}else{$quer=mysql_query("SELECT DISTINCT proddetfield FROM productdetail order by proddetfield"); }
////////// end of query for second subcategory drop down list box ///////////////////////////
/////// for third drop down list we will check if category is selected else we will display all the subcategory/////
if(isset($cat) and strlen($cat) > 0){
$quer1=mysql_query("SELECT DISTINCT prodqualfield FROM productquality where prodid=$cat order by prodqualfield");
}else{$quer1=mysql_query("SELECT DISTINCT prodqualfield FROM productquality order by prodqualfield"); }
////////// end of query for third subcategory drop down list box ///////////////////////////
?>
<form method="post" name="prodform" action="dd-check.php">
<div id="topl">
<div class ="toplpost">
<h1 class="title"> Select a product </h1>
<div class="entry">
<select name="prodid" onchange="reload(this.form)">
<?php
while($noticia2 = mysql_fetch_array($quer2))
{
if($noticia2['prodid']==@$cat){echo "<option selected value='$noticia2[prodid]'>$noticia2[prodname]</option>"."<BR>";}
else{echo "<option value='$noticia2[prodid]'>$noticia2[prodname]</option>";}
//$selected = ($prodrow1['prodid']==$_SESSION['prodid']) ? ' selected="selected"' : '';
//echo "<option value=\"{$prodrow1['prodid']}\"{$selected}>{$prodrow1['prodname']}</option>\n";
} ?>
</select>
<?php
////////// Starting of second drop downlist /////////
echo "<select name='subcat'><option value=''>Select one</option>";
while($noticia = mysql_fetch_array($quer)) {
echo "<option value='$noticia[proddetfield]'>$noticia[proddetfield]</option>";
}
echo "</select>";
thanks for any help, hopefully it will just be a case of calling the function that populates the product fields somewhere else!