-
I have a dropdownlist on a form that contains data from a stored cookie. This is so the user has a dropdown filled with data specific to them.
What I want to do is let the user type in another value other than listed in the dropdown. Is there a way for the user to type in a value at the top of the list displayed in the dropdown?
I think I have seen this done but am not sure how to do it.
Thanks!
~Piz
-
Hi Piz,
Here is what i came up with.
Hope this helps
Code:
<html>
<head>
<script>
function additem(itemname)
{
if (itemname=="" )
{
alert ("Please enter any text");
return false;
}
var n;
n=document.frm1.cmb1.options.length;
var myArr = new Array (n);
for (i=0;i<n;i++)
{
myArr[i]=document.frm1.cmb1.options[i].text;
}
document.frm1.cmb1.options[0]=new Option(itemname);
for (j=0;j<myArr.length;j++)
{
document.frm1.cmb1.options[j+1]= new Option(myArr[j]);
}
document.frm1.cmb1.selectedIndex=0;
}
</script>
<title>Dan's AddItem</title></head>
<BODY bgcolor="#FFFFFF" >
<form name=frm1>
<select name=cmb1 >
<option value="Item1">Item1</option>
<option value="Item2">Item2</option>
</select>
<input name=txt1 >
<input type="button" name="Button" value="Add Item" onclick="javascript:additem(document.frm1.txt1.value)">
</form>
</body>
</html>
-
thanks
Thanks! I will give this a shot......
~Piz