Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dropdown list custom entry

Status
Not open for further replies.

Killborg

Technical User
Jul 16, 2007
46
US
Can I make a dropdown list where if the user does not see the item in the list they can type it in.
 
Hi

Some time ago I saw some Explorer only solutions. ( But while I was not interested, I did not bookmarked the page. )

Normally you can not do that directly. But you can with an additional [tt]input[/tt].
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/strict.dtd">[/URL]
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<title></title>
<script type="text/javascript">
function plus()
{
  var sel=document.getElementById('sel')
  var add=document.getElementById('add')
  sel.options[sel.options.length]=new Option(add.value)
  sel.selectedIndex=sel.options.length-1
}
</script>
<body>
<form action="">
<p>
<select name="sel" id="sel">
<option>One</option>
<option>Two</option>
</select>
<input type="text" name="add" id="add" value="">
<input type="button" value="+" onclick="plus()">
</p>
</form>
</body>
</html>

Feherke.
 
Hi

Or the same with a nicer look.
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/strict.dtd">[/URL]
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<title></title>
<style type="text/css">
select#sel,input#add {
  width: 100px;
}
input#add {
  position: absolute;
  visibility: hidden;
}
</style>
<script type="text/javascript">
function plus()
{
  var sel=document.getElementById('sel')
  var add=document.getElementById('add')
  var ch=sel.style.visibility=='hidden'
  sel.style.visibility=ch?'visible':'hidden'
  add.style.visibility=ch?'hidden':'visible'
  if (ch) {
    sel.options[sel.options.length]=new Option(add.value)
    add.value=''
    sel.selectedIndex=sel.options.length-1
  }
}
</script>
<body>
<form action="">
<p>
<input type="text" name="add" id="add" value="">
<select name="sel" id="sel">
<option>One</option>
<option>Two</option>
</select>
<input type="button" value="+" onclick="plus()">
</p>
</form>
</body>
</html>

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top