Dynamiske selectboxe - find fejlen
Jeg har stirret mig blind tror jeg, er der en der kan fortælle mig hvorfor min select nummer 2 ikke virker som den skal?http://d2171880.u51.surftown.dk/timesag/ts_dynamic_select.php
KODE:
<html>
<body>
<?php
//$select_name: The name of the selectbox as in name=""
//$css_class: The css class u use to style the selectbox, "" if you are not using
//$table_name: The name of the table from which you get your selectbox values
//$id_field_name: The name of the id field in the table you get your values from
//$id_from_url: An id used to determine what value is currently selected (either from get or post)
//$face_value_field: The name of the field in the database table that you want to be shown in the selectbox <option>
function KDJ_dynamic_select ($select_name, $css_class, $table_name, $id_field_name, $id_from_url, $face_value_field){
$sql = "SELECT * FROM $table_name";
$res = mysql_query($sql);
echo'<select name="'.$select_name.'" onChange="Load_id()">';
while($row = mysql_fetch_array($res)) {
$selected = ($row[$id_field_name] == $id_from_url)? "SELECTED":"";
echo"<option value=\"".$row[$id_field_name]."\"". $selected." >".$row[$face_value_field]."</option>";
}//hile
echo"</select>";
}//end func
function KDJ_select_from_query ($select_name, $css_class, $table_name, $id_field_name, $field_to_match, $id_to_match, $face_value_field){
$sql = "SELECT * FROM $table_name WHERE $field_to_match == $id_to_match";
echo $sql;
$res = mysql_query($sql);
echo'<select name ="'.$select_name.'">';
while($row = mysql_fetch_array($res)) {
echo"<option value=\"".$row[$id_field_name]."\">".$row[$face_value_field]."</option>";
}
echo"</select></form>";
}//end func
$id = $_GET[id];
include_once("connect.php");
include_once("form_lib.php");
echo '<form name="testform">';
KDJ_dynamic_select ("ts_projekt_id", "", "ts_projekter", "ts_projekt_id", $id, "ts_projekt_navn");
KDJ_select_from_query ("ts_opgave_id", "", "ts_opgaver", "ts_opgave_id", "ts_opgave_projekt_id", $id, "ts_opgave_navn");
KDJ_list_table ("ts_projekter");
echo '<hr>';
KDJ_list_table ("ts_opgaver");
echo'</form>';
?>
<script type="text/javascript">
function Load_id()
{
var id = document.testform.ts_projekt_id.options[document.testform.ts_projekt_id.selectedIndex].value
var id_txt = "?id="
location = id_txt + id
}
</script>
<body>
<html>