title image


Smiley Re: dynamische dropdownbox
Kleines Beispiel



<html>

<head>

<style type="text/css">

<!--

select { width: 100px; }

//-->

</style>

<script type="text/javascript" language="javascript">

<!--

var daten=new Array();

var d1="";

var d2="";

function addData(sdrop1,sdrop2,sdrop3) {

this.drop1=sdrop1;

this.drop2=sdrop2;

this.drop3=sdrop3;

}

function changeSelect1(n) {

s1=document.fform1.sdrop1;

s2=document.fform1.sdrop2;

s3=document.fform1.sdrop3;

d1=s1.options[s1.selectedIndex].value;

d2=(s2.length>0)?s2.options[s2.selectedIndex].value:"";

if (d1=="") {

s2.length=0;

s3.length=0;

return;

}

i=0; while (i<daten.length&&daten[i].drop1!=d1) i++;

if (!n) {

d2="";

s2.length=0;

s2.options[0]=new Option('','');

while (i<daten.length&&daten[i].drop1==d1) {

if (daten[i].drop2!=d2) {

d2=daten[i].drop2;

s2.options[s2.options.length]=new Option(daten[i].drop2,daten[i].drop2);

}

i++;

}

d2="";

}

s3.length=0;

if (d2!="") {

s3.options[0]=new Option('','');

i=0; while ((i<daten.length)&&((daten[i].drop1!=d1)||(daten[i].drop2!=d2))) i++;

while (i<daten.length&&daten[i].drop1==d1&&daten[i].drop2==d2) {

s3.options[s3.options.length]=new Option(daten[i].drop3,daten[i].drop3);

i++;

}

}

}

<?

$host="dein host";

$base="deine datenbank";

$user="dein User";

$pass="dein Passwort";

$sql="SELECT drop1, drop2, drop3 FROM dropdown ORDER BY drop1, drop2, drop3";

$db=mysql_connect($host,$user,$pass) or die("Mysql-Fehler: ".mysql_error());

mysql_select_db($base) or die("Mysql-Fehler: ".mysql_error());

$result=mysql_query($sql,$db) or die("Mysql-Fehler: ".mysql_error());

$drop1=Array();

$d1="";

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

echo "daten[daten.length]=new addData('".$row[0]."','".$row[1]."','".$row[2]."');\n";

if ($d1!=$row[0]) {

$drop1[]=$row[0];

$d1=$row[0];

}

}

mysql_close();

?>

//-->

</script>

</head>

<body>

<form name="fform1">

<select name="sdrop1" onchange="changeSelect1(0);">

<option></option>

<? foreach ($drop1 as $v) echo "<option value=\"".$v."\">".$v."</option>\n"; ?>

</select>

<select name="sdrop2" onchange="changeSelect1(1);">

</select>

<select name="sdrop3">

</select>

</form>

</body>

</html>








cu
Ich bin wie ich bin
Die mich kennen mögen mich
die mich nicht mögen können mich


geschrieben von

Login

E-Mail:
  

Passwort:
  

Beitrag anfügen

Symbol:
 
 
 
 
 
 
 
 
 
 
 
 
 

Überschrift: