Jump to content

Populating multiple drop down (dynamic) boxes

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
Astha

Astha

    Newbie

  • Members
  • PipPip
  • 25 posts
Hi,

I'm creating one form which has all drop down lists. Please see the attached screenshot.

Currently, I'hv just created a basic outline of the form. I want the form to work like this:

    Upon selection of Product Name, corresponding values of Design ID (related to that product name) should be displayed in the second drop down i.e. Design ID.

    Upon selection of Design ID, corresponding property names (related to that design ID), i.e. paper type, product size, paper color, etc should be listed. At the same time corresponding property values (in form of drop down) should be displayed next to each property name, respectively.

Can somebody give me an idea of how to achieve this.

Thanks in advance.

Attached Files

  • Attached File  SC.png   10.15K   100 downloads


#2
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
this is usually made with ajax calls on the onchange event of the drop boxes, so you would
a) need a ajax returning script file, most likely php which is returning an xml or json strycture to your page
b) a javascript for each drop box, reading values from a) and populates them in next drop box
c) a javascript that supervises all the boxes, so if a user changes an earlier selection, it restarts from that box, or, inactivates already choosen boxes and use a reset button instead
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#3
Astha

Astha

    Newbie

  • Members
  • PipPip
  • 25 posts
Hi All,

Appreciate you replies, but I'm not supposed to use Ajax for this project. Can I do this only in java script? If yes, how?

Thanks

#4
Astha

Astha

    Newbie

  • Members
  • PipPip
  • 25 posts
Hi,

I could display Product Name drop down box, Design ID drop down box, and could list Property Names. Initially, the php page displays:

    Product Name drop down box (works)
    Design ID drop down box (works, i.e., upon selection of Product Name corresponding Design ID values are displayed in this box)
    Lists all available property names from property table (Doesn't work)

Issue: Initially, all Property Names are displayed. But upon selection of Design ID, the list disappears. Instead it should display the Property Names applicable to the selected Design ID.

Here's my code:

<?php


$dbservertype='mysql';

$servername='localhost';

$dbusername='root';

$dbpassword='';

$dbname='templetree';


connecttodb($servername,$dbname,$dbusername,$dbpassword);

function connecttodb($servername,$dbname,$dbuser,$dbpassword)

{

global $link;

$link=mysql_connect ("$servername","$dbuser","$dbpassword");

if(!$link){die("Could not connect to MySQL");}

mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error());

}


?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

<SCRIPT language=JavaScript>

function reload(form)

{

var val=form.products.options[form.products.options.selectedIndex].value;

self.location='design_form_working.php?products=' + val ;

}

function reload3(form)

{

var val=form.products.options[form.products.options.selectedIndex].value;

var val2=form.design.options[form.design.options.selectedIndex].value; 


self.location='design_form_working.php?products=' + val + '&design=' + val2 ;

}



</script>

</head>


<body>


<?php


$quer2=mysql_query("SELECT * FROM products"); 


@$products=$_GET['products'];

if(isset($products)){

$quer=mysql_query("SELECT * FROM sample_design WHERE product_ID=$products"); 

}else{$quer=mysql_query("SELECT * FROM sample_design"); } 


@$design=$_GET['design']; 

if(isset($design)){

$quer3="SELECT * FROM sample_design, design_detail, property WHERE sample_design.product_ID=design_detail.product_ID AND design_detail.property_ID=property.property_ID AND design_detail.design_ID=$products"; 

$result = mysql_query($quer3) or die(mysql_error());

}else{$quer3="SELECT * FROM property"; 

$result = mysql_query($quer3) or die(mysql_error());} 


?>




<form name="f1" method="post" action="dd-check.php">


<?php


echo "<br><select name='products' onchange=\"reload(this.form)\"><option value=''>Select one</option>";

while($noticia2 = mysql_fetch_array($quer2)) { 

if($noticia2['product_ID']==@$products){echo "<option selected value='$noticia2[product_ID]'>$noticia2[product_name]</option>"."<BR>";}

else{echo  "<option value='$noticia2[product_ID]'>$noticia2[product_name]</option>";}

}

echo "</select>";



echo "<br><br><br><select name='design' onchange=\"reload3(this.form)\"><option value=''>Select one</option>";

while($noticia = mysql_fetch_array($quer)) { 

if($noticia['design_ID']==@$design)

{echo "<option selected value='$noticia[design_ID]'>$noticia[design_ID]</option>"."<BR>";}

else{echo  "<option value='$noticia[design_ID]'>$noticia[design_ID]</option>";}

}

echo "</select>"."<BR>"."<BR>";





while($noticia = mysql_fetch_array($result)) { 

echo  "<BR>"."$noticia[property_name]"."<BR>";

}



echo "<BR>"."<BR>"."<input type=submit value=Submit>";


?>



	 

</form>

</body>

</html>



Please help!