通过在firstdropdown中消失所选值,根据第一个结果选择第二个下拉列表

时间:2014-03-12 13:07:12

标签: javascript php jquery html

<head>

中的Javascript
var val=form.rmmm.options[form.rmmm.options.selectedIndex].value; 
self.location='call.php?rmmm=' + val ;

PHP

<?php

$host= "host=localhost";
$port= "port=5432";
$dbname= "dbname=postgres";
$credentials= "user=postgres password=pgadmin";

$db= pg_connect("$host $port $dbname $credentials");

if(!$db)
{
    echo "not connect";
}


$rmquery = "SELECT DISTINCT rmname,rmid FROM  room ORDER  BY rmname";
$resultrm = pg_query($db, $rmquery); 

$rmmm=$_GET['rmmm'];
if(strlen($rmmm)>0 and !is_numeric($rmmm))
{
    echo "data error";
    exit;
}
if(isset($rmmm) and strlen($rmmm)>0)
{
    $bedquery = "SELECT DISTINCT bedid,bednum FROM bed  where >rmid=$rmmm";
    $resultbed = pg_query($db, $bedquery);
}
else
{
    $bedquery = "SELECT DISTINCT bedid,bednum FROM bed";
    $resultbed = pg_query($db, $bedquery);
}

echo "<form method=post name=f1 action=''> ";
// first dropdownin a missing value--

 //- List item

echo "<select name='rmmm' onchange=\"reload(this.form)\"><option >value=''>Select Room</option>";
while($row = pg_fetch_row( $resultrm )) 
{
    if($row['rmid']==$rmmm)
        echo '<option selected="selected" value= "' . $row[1] . '">' . $row[0] . >'</option>';
    }
    else {
        echo '<option  value= "' . $row[1] . '">' . $row[0] . >'</option>';
    }
}
echo "</select>";

//second dropdown
echo "<select name='bednam'><option value=''>Select Bed</option>";
while($rw = pg_fetch_row($resultbed)) 
{
    echo '<option value= "' . $rw[0] . '">' . $rw[1] . '</option>';
}
echo "</select>";
echo "</form>";

?>  

0 个答案:

没有答案