Populating list box via selection from form drop down

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Frapster
Forum Newbie
Posts: 22
Joined: Thu Jan 06, 2005 8:42 am

Populating list box via selection from form drop down

Post by Frapster »

Ok - after spending a day working on this I have found the following solution from Macromedia. It looks awesome and in the process I've learned how to more integrate the features of Dreamweaver MX into my development process.

The only problem I have is the darn thing doesn't work! lol I've followed the instructions in setting all this up and it should work but noooo... not for me it isn't. ;)

If someone has the time to look this over - can you maybe identify any problems?

Thanks in advance.

PS - I tried to use the

Code: Select all

blocks but it doesn't work.

Code: Select all

<?php require_once('../Connections/dbLamps.php'); ?>
<?php
mysql_select_db($database_dbLamps, $dbLamps);
$query_rsLamps = \\"SELECT family2.family_name, family2.id FROM family2 ORDER BY family2.family_name\\";
$rsLamps = mysql_query($query_rsLamps, $dbLamps) or die(mysql_error());
$row_rsLamps = mysql_fetch_assoc($rsLamps);
$totalRows_rsLamps = mysql_num_rows($rsLamps);

mysql_select_db($database_dbLamps, $dbLamps);
$query_rsTypes = \\"SELECT lamp_type2.id, lamp_type2.family, lamp_type2.name FROM lamp_type2\\";
$rsTypes = mysql_query($query_rsTypes, $dbLamps) or die(mysql_error());
$row_rsTypes = mysql_fetch_assoc($rsTypes);
$totalRows_rsTypes = mysql_num_rows($rsTypes);
?>
<%@LANGUAGE=\\"JAVASCRIPT\\" CODEPAGE=\\"1252\\"%>
<!DOCTYPE HTML PUBLIC \\"-//W3C//DTD HTML 4.01 Transitional//EN\\" \\"http://www.w3.org/TR/html4/loose.dtd\\">
<html>
<head>
<meta http-equiv=\\"Content-Type\\" content=\\"text/html; charset=iso-8859-1\\">
<title>Lamps Database Admin</title>
<style type=\\"text/css\\">
<!--
body {
	background-color: #999999;
}
.style3 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 14px;
	font-weight: bold;
}
.style17 {font-family: Arial, Helvetica, sans-serif; font-size: 12px; }
.style34 {font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; }
.style36 {
	font-size: 11px;
	font-weight: bold;
}
.style38 {font-family: Arial, Helvetica, sans-serif; font-size: 14px; font-weight: bold; color: #990000; }
.style40 {color: #990000}
.style41 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 11px;
}
.style42 {color: #000000}
-->
</style>
<!-- Dynamic Dependent List box Code for *** JavaScript *** Server Model //-->
<script language=\\"JavaScript\\">
<!--
var arrDynaList = new Array();
var arrDL1 = new Array();
arrDL1[1] = \\"lampname\\"; // Name of parent list box
arrDL1[2] = \\"formLamp\\"; // Name of form containing parent list box
arrDL1[3] = \\"lamptype\\"; // Name of child list box
arrDL1[4] = \\"formType\\"; // Name of form containing child list box
arrDL1[5] = arrDynaList;
<%
var txtDynaListRelation, txtDynaListLabel, txtDynaListValue, oDynaListRS;
txtDynaListRelation = \\"lamp_type2.family\\" // Name of recordset field relating to parent
txtDynaListLabel = \\"lamp_type2.name\\" // Name of recordset field for child Item Label
txtDynaListValue = \\"lamp_type2.id\\" // Name of recordset field for child Value
oDynaListRS = rsTypes // Name of child list box recordset
var varDynaList = -1;
var varMaxWidth = \\"1\\";
var varCheckGroup = oDynaListRS.Fields.Item(txtDynaListRelation).Value;
var varCheckLength = 0;
var varMaxLength = 0;
while (!oDynaListRS.EOF){
 if (varCheckGroup != oDynaListRS.Fields.Item(txtDynaListRelation).Value) {
  varMaxLength = Math.max(varCheckLength, varMaxLength)
  varCheckLength = 0;
 }
%>
 arrDynaList[<%=(varDynaList+1)%>] = \\"<%=(oDynaListRS.Fields.Item(txtDynaListRelation).Value)%>\\";
 arrDynaList[<%=(varDynaList+2)%>] = \\"<%=(oDynaListRS.Fields.Item(txtDynaListLabel).Value)%>\\";
 arrDynaList[<%=(varDynaList+3)%>] = \\"<%=(oDynaListRS.Fields.Item(txtDynaListValue).Value)%>\\";
<%
 if (oDynaListRS.Fields.Item(txtDynaListLabel).Value.length > varMaxWidth.length) {
  varMaxWidth = oDynaListRS.Fields.Item(txtDynaListLabel).Value;
 }
 varCheckLength = varCheckLength + 1;
 varDynaList = varDynaList + 3;
 oDynaListRS.MoveNext();
}
varMaxLength = Math.max(varCheckLength, varMaxLength)
%>
//-->
</script>
<!-- End of object/array definitions, beginning of generic functions -->
<script language=\\"JavaScript\\">
<!--
function setDynaList(arrDL){
 var oList1 = document.forms[arrDL[2]].elements[arrDL[1]]
 var oList2 = document.forms[arrDL[4]].elements[arrDL[3]]
 var arrList = arrDL[5]
 
 clearDynaList(oList2);
 
 if (oList1.selectedIndex == -1){
  oList1.selectedIndex = 0;
 }
 populateDynaList(oList2, oList1[oList1.selectedIndex].value, arrList);
 return true;
}
 
function clearDynaList(oList){
 for (var i = oList.options.length; i >= 0; i--){
  oList.options[i] = null;
 }
 
 oList.selectedIndex = -1;
}
 
function populateDynaList(oList, nIndex, aArray){
 for (var i = 0; i < aArray.length; i= i + 3){
  if (aArray[i] == nIndex){
   oList.options[oList.options.length] = new Option(aArray[i + 1], aArray[i + 2]);
  }
 }
 if (oList.options.length == 0){
  oList.options[oList.options.length] = new Option(\\"[none available]\\",0);
 }
 
 oList.selectedIndex = 0;
}

function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}
//-->
</script>

</head>
<body onLoad=\\"MM_callJS('setDynaList(arrDL1)')\\">
<table width=\\"100%\\" height=\\"100%\\"  border=\\"0\\" cellpadding=\\"0\\" cellspacing=\\"0\\">
  <tr>
    <td align=\\"center\\" valign=\\"middle\\"><table width=\\"60%\\"  border=\\"0\\" align=\\"center\\" cellpadding=\\"5\\" cellspacing=\\"2\\" bgcolor=\\"#FFFFFF\\">
        <tr>
          <td align=\\"center\\" valign=\\"top\\" bgcolor=\\"#CCCCCC\\"><span class=\\"style3\\">Navigation Goes Here </span></td>
        </tr>
        <tr>
          <td valign=\\"top\\"><table width=\\"100%\\"  border=\\"0\\" cellspacing=\\"2\\" cellpadding=\\"5\\">
              <tr valign=\\"top\\">
                <td width=\\"50%\\"><hr size=\\"3\\" noshade color=\\"#000000\\">
                </td>
              </tr>
              <tr valign=\\"top\\">
                <td bgcolor=\\"#D3FFDA\\"><span class=\\"style3\\">Define Lamp Compatibility</span></td>
              </tr>
              <tr valign=\\"top\\">
                <td>                  
                    <table width=\\"100%\\"  border=\\"0\\" cellpadding=\\"3\\" cellspacing=\\"1\\" bgcolor=\\"#666666\\">
                      <tr align=\\"center\\" valign=\\"top\\" bgcolor=\\"#CCCCCC\\">
                        <td><span class=\\"style34\\">Pick a Lamp Family Name </span></td>
                        <td><span class=\\"style34\\">Choose Lamp Type </span></td>
                        <td><span class=\\"style34\\">Click this button to submit change. </span></td>
                      </tr>
                      <tr align=\\"center\\" valign=\\"top\\" bgcolor=\\"#FFFFFF\\">
                        <td width=\\"33%\\"> <form action=\\"fam_add_del.php\\" method=\\"post\\" name=\\"formLamp\\" id=\\"formLamp\\">
                          <select name=\\"lampname\\" id=\\"lampname\\" onChange=\\"MM_callJS('setDynaList(arrDL1)')\\">
                          <option value=\\"\\" selected>Please Choose One</option>
                          <?php
do {  
?>
                          <option value=\\"<?php echo $row_rsLamps['id']?>\\"><?php echo $row_rsLamps['family_name']?></option>
                          <?php
} while ($row_rsLamps = mysql_fetch_assoc($rsLamps));
  $rows = mysql_num_rows($rsLamps);
  if($rows > 0) {
      mysql_data_seek($rsLamps, 0);
	  $row_rsLamps = mysql_fetch_assoc($rsLamps);
  }
?>
                        </select> </form> </td>
                        <td width=\\"33%\\"><form action=\\"view_fam_type2.php\\" method=\\"post\\" name=\\"formType\\" id=\\"formType\\"> 
                          <select name=\\"lamptype\\" size=\\"5\\" id=\\"lamptype\\">
                              </select> </form> </td>
                        <td width=\\"33%\\"> <form action=\\"view_fam_type2.php\\" method=\\"post\\" name=\\"formCreate\\" id=\\"formCreate\\"> 
                          <select name=\\"replacement\\" id=\\"replacement\\">
                          <option value=\\"\\" selected>Please Choose One</option>
                          <?php
do {  
?>
                          <option value=\\"<?php echo $row_rsLamps['id']?>\\"><?php echo $row_rsLamps['family_name']?></option>
                          <?php
} while ($row_rsLamps = mysql_fetch_assoc($rsLamps));
  $rows = mysql_num_rows($rsLamps);
  if($rows > 0) {
      mysql_data_seek($rsLamps, 0);
	  $row_rsLamps = mysql_fetch_assoc($rsLamps);
  }
?>
                        </select> </form> </td>
                      </tr>
                      <tr align=\\"center\\" valign=\\"top\\" bgcolor=\\"#FFFFFF\\">
                        <td colspan=\\"3\\"><input name=\\"create\\" type=\\"submit\\" id=\\"create\\" value=\\"Create Compatibility\\"></td>
                      </tr>
                      <tr align=\\"center\\" valign=\\"top\\" bgcolor=\\"#FFFFFF\\">
                        <td colspan=\\"3\\"><span class=\\"style41\\">Choose the lamp to modify from the drop-down list at left. Enter the new name in the field at center. <br>
And then click on the 'submit' button to update the Lamp Family name.</span></td>
                      </tr>
                    </table>
                  
                </td>
              </tr>
            </table></td>
        </tr>
        <tr>
          <td align=\\"center\\" valign=\\"top\\" bgcolor=\\"#CCCCCC\\"><span class=\\"style17\\">Visit the lamps compatibility page on the Australian Gold website by <a href=\\"http://www.australiangold.com/lamps/lamps.asp\\" target=\\"_blank\\">clicking here</a><br>
            to verify the information you've entered or modified while using this control panel. </span></td>
        </tr>
      </table></td>
  </tr>
</table>
</body>
</html>
<?php
mysql_free_result($rsLamps);

mysql_free_result($rsTypes);
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

this sure looks like ASP stuffs to me.

so let me get this straight, you want to toss a selection from one list to another, with or without a page refresh required? It looks like without..

here's a thread where we created a this sort of "feature"
viewtopic.php?t=21250


btw, if you read the general dicussion board about "what happened", you'll understand why the

Code: Select all

tags don't work right now.
Post Reply