当前位置:Linux教程 - Php - 让下拉列表又能选择又能输入

让下拉列表又能选择又能输入

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function catch_keydown(sel)
{
switch(event.keyCode)
{
case 13:
//Enter;
sel.options[sel.length] = new Option("","",false,true);
event.returnValue = false;
break;
case 27:
//Esc;
alert("text:" + sel.options[sel.selectedIndex].text + ", value:" + sel.options[sel.selectedIndex].value + ";");
event.returnValue = false;
break;
case 46:
//Delete;
if(confirm("删除当前选项!?"))
{
sel.options[sel.selectedIndex] = null;
if(sel.length>0)
{
sel.options[0].selected = true;
}
}
event.returnValue = false;
break;
case 8:
//Back Space;
var s = sel.options[sel.selectedIndex].text;
sel.options[sel.selectedIndex].text = s.substr(0,s.length-1);
event.returnValue = false;
break;
}
}
function catch_press(sel)
{
sel.options[sel.selectedIndex].text = sel.options[sel.selectedIndex].text + String.fromCharCode(event.keyCode);
event.returnValue = false;
}
//End -->
</script>

</head>
<select size="1" name="fh_cp" onKeyDown="catch_keydown(this);" onKeyPress="catch_press(this);" style="font-size:12px;">
<option></option>
<?if ($FH_CP<>""){
$seek_cp="select gg,cp from bom where lh='$FH_CP' ";
$result_cp=@pg_exec($link,$seek_cp);
$GG=trim(pg_result($result_cp,0,"gg"));
$CP=trim(pg_result($result_cp,0,"cp"));
$C_G=$CP.' '.$GG;

echo
"<option selected value=\"$FH_CP\">$C_G</option>"; }?>
<?
for($j=0;$j<$row_fh;$j++){
$gg_fh=trim(pg_result($result_fh,$j,"gg"));
$cp_fh=trim(pg_result($result_fh,$j,"cp"));
$seek_lh="select * from bom where cp='$cp_fh' and gg='$gg_fh' ";
$result_lh=pg_exec($link,$seek_lh);
$lh_fh=trim(pg_result($result_lh,0,"lh"));
$cp_gg=$cp_fh.' '.$gg_fh;

if(
$lh_fh==$FH_CP){
echo
"<option selected value=\"$lh_fh\">$cp_gg</option>";
}
else{
echo
"<option value=\"$lh_fh\">$cp_gg</option>";
}
}
?>
</select>