Problem with dynamic populating the drop down list based on the selected value of first list

mboodhoo
05:13:11
Hello

I made use of the code provided here to try to populate a second dropdown list based on selected value from first dropdown list: http://www.plus2net.com/php_tutorial/php_drop_down_list.php

I am getting error: Undefined index sel_proc in my php file.

Here is my code:
1 - PHP
// fetch list of procedures
$list_proc = oci_parse($c, "select proc_refe from capa_proc order by proc_refe");
oci_execute($list_proc, OCI_DEFAULT);

echo "<select name='proc' style='position:absolute; left:20%; top:39%; width:200px' onchange='populateProcCatg(this.form)'>";

// fill in drop down list Procedure
while ($proc = oci_fetch_array($list_proc, OCI_ASSOC+OCI_RETURN_NULLS))
{
echo "<option value='" . $proc['PROC_REFE'] . "'>" . $proc['PROC_REFE'] . "</option>";
}

// fill in the Procedure Category drop down list
// based on the selected Procedure
$sel_proc = $_GET['proc'];

// if user has selected a value from Procedure list
if (isset($sel_proc) and strlen($sel_proc) > 0)
{
// display selected value in Procedure list
echo "<option selected value='" . $sel_proc . "'>" . $sel_proc . "</option>";
echo "</select>";
}
else
{
// do not select any value
echo "</select>";
}

// display drop down list Procedure Category with no values
echo "<select name='catg' style='position:absolute; left:60%; top:39%; width:200px'>";

// if user has selected a value from Procedure list
if (isset($proc) and strlen($proc) > 0)
{
// fetch list of categories corresponding to selected procedure
$list_catg = oci_parse($c, "select catg_desc
from proc_catg
where proc_refe = :bind1
order by catg_desc");
oci_bind_by_name($list_catg, ":bind1", $proc);
oci_execute($list_catg, OCI_DEFAULT);

while ($catg = oci_fetch_array($list_catg, OCI_ASSOC+OCI_RETURN_NULLS))
{
echo "<option value='" . $catg['CATG_DESC'] . "'>" . $catg['CATG_DESC'] . "</option>";
}
}
echo "</select>";

2- Javascript
function populateProcCatg(form)
{
var selectedProc = form.proc.options[form.proc.options.selectedIndex].value;

self.location = 'capa_support.php?sel_proc=' + selectedProc;
}
mboodhoo
05-17-2011
Problem solved - i had more than one elements with same ID in my form... fixed it. Code works.
Please Login to post your reply or start a new topic