求表单下拉框:既可以手动输入,也可以下拉选择已有数据!

somecom 2003-08-19 10:11:21
各位大侠,求助!
求表单下拉框:既可以手动输入,也可以下拉选择已有数据!
还有,那位大侠有Fontpage里的表单项:列表表单、列表域?我的软件上的两个选项是灰色的,无论怎样添加都出不来!
谢过了!

<select size="1" name="D1">这里的值既可以物动输入,也可以下拉选择已有数据!</select>
...全文
1151 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
coffee_cn 2003-08-20
  • 打赏
  • 举报
回复
刚才贴的代码不能正常运行,现在修改了下:

<body onload="s1.focus();">
<script language="JavaScript">
<!--
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;
}
//-->
</script>
<form name=form1 action=selectok.asp>
<select name=s1 onkeydown="catch_keydown(this);" onkeypress="catch_press(this);" style="font-size:12px;"><option>---</option></select>
<BR>按回車輸入新內容,按DEL刪除選中內容
<br><input type=submit>
</form>
</body>
yyy431706 2003-08-20
  • 打赏
  • 举报
回复
对不起,代码应该是这样的,在onload事件中先隐藏文本框,然后用按钮的单击事件隐藏下拉框,显示文本框 。
<html>
<head>
<script language="javascript">
function show_text()

{

a.style.visibility="hidden";
b.style.visibility="visible";

}
function hidden_text()
{
b.style.visibility="hidden";
}
</script>
</head>
<body onload="hidden_text()">
<form>
<table>
<tr>
<td>
事故地段:
<div id="a" style="position:absolute; margin-left:0px; margin-top:-3px; width:350px; height:0px; z-index:0; background-color:; border: 0px; solid: #000000; padding:1px">
<select name="sgdd">
<option value="1" selected>1</option>
<option value="2">2</option>
<option value="3">3</option>
</select><input type="button" value="添加" onClick="show_text()">
</div>
<div id="b" style="position:absolute; margin-left:0px; margin-top:-3px; width:250px; height:0px; z-index:0; background-color:; border: 0px; solid: #000000; padding:1px">
<input name="sgdd_text" type="text">
</div>
</td>
</tr>
</table>
</form>
</body>
</html>
yyy431706 2003-08-20
  • 打赏
  • 举报
回复
我前几天也碰到这样的问题,这是我摸索出的一个解决方法,
如果下拉框中没有你所要的数据,
可在点点击添加按钮将下拉框隐藏,显示文本框进行输入.
主要用到css的相对定位和绝对定位实现。
我现在就用的是这个,有问题给我发消息。
<script language="javascript">
function show_text()

{

a.style.visibility="hidden";
b.style.visibility="visible";

}
</script>
<form>
<table>
<tr>
<td>
事故地段:
<div id="a" style="position:absolute; margin-left:0px; margin-top:-3px; width:350px; height:0px; z-index:0; background-color:; border: 0px; solid: #000000; padding:1px">
<select name="sgdd">
<option value="1" selected>1</option>
<option value="2">2</option>
<option value="3">3</option>
</select><input type="button" value="添加" onClick="show_text()">
</div>
<div id="b" style="position:absolute; margin-left:0px; margin-top:-3px; width:250px; height:0px; z-index:0; background-color:; border: 0px; solid: #000000; padding:1px">
<input name="sgdd_text" type="text">
</div>
</td>
</tr>
</table>
</form>
coffee_cn 2003-08-20
  • 打赏
  • 举报
回复
别人的例子
<body onload="s1.focus();">
<script language="JavaScript">
<!--
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;
}
//-->
</script>
<select name=s1 onkeydown="catch_keydown(this);" onkeypress="catch_press(this);" style="font-size:12px;"><option>---</option></select>
<BR>按回車輸入新內容,按DEL刪除選中內容
</body>
甘泉123 2003-08-20
  • 打赏
  • 举报
回复
楼上的好象答非所问,不过挺有用~~~
继续关注
zorou_fatal 2003-08-19
  • 打赏
  • 举报
回复

<%
Response.Write Request.Form("listvalues")
%>
<script>
function dellist()
{
if (window.form1.sel1.lastChild!="")
{
window.form1.sel1.removeChild(window.form1.sel1.lastChild);
}


}

function addtolist()
{
if( window.form1.txt1.value!="" )
{
window.form1.listvalues.value=window.form1.listvalues.value+window.form1.txt1.value+",";
myEle = document.createElement("option") ;
myEle.text = window.form1.txt1.value;
window.form1.sel1.add(myEle);
}

}
</script>
<script>
function listsubmit()
{
window.form1.submit()
}
</script>
<form id="form1" action="" method=post>
<select name="sel1">
<option>1</option>
<option>2</option>
<option>3</option>
</select>
<input type="hidden" name="listvalues">
<input type="text" name="txt1">
<input type="button" value="填入列表" onclick="addtolist()"><input type="button" value="提交" onclick="listsubmit()">
<input type="button" value="删除" onclick="dellist()">
</form>

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧