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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can combo boxes be combined with text boxes? 1

Status
Not open for further replies.

tdion

MIS
Dec 18, 2003
61
US
I'd like the user to be able to type in the text box area of my combo box, and have it autofill with a value in the dropdown list.

Right now I'm using the standard "<SELECT>" combo box tags and the user can't enter any text.

Thanks in advance.
 

There is no combo box control - you'd have to combine a text box and a select box. Something like this should get you started:

Code:
<html>
<head>
<style type="text/css">
</style>

<script type="text/javascript">
<!--
	function updateSelect(str)
	{
		if (!str || str == '') return;
		var selObj = document.forms['myForm'].mySelect;
		for (var loop=0; loop<selObj.options.length; loop++) {
			if (selObj.options[loop].text.toLowerCase().indexOf(str.toLowerCase()) == 0) {
				selObj.selectedIndex = loop;
				break;
			}
		}
	}
//-->
</script>

</head>
<body>
	<form name="myForm">
		<input type="text" onkeyup="updateSelect(this.value);" style="width:150px;"><br>
		<select name="mySelect" style="width:150px;">
			<option value="1">Audi</option>
			<option value="1">Bentley</option>
			<option value="1">BMW</option>
			<option value="1">Ford</option>
			<option value="1">Mercedes</option>
			<option value="1">Mitsubishi</option>
			<option value="1">Saab</option>
			<option value="1">Subaru</option>
			<option value="1">Toyota</option>
		</select>
	</form>
</body>
</html>

Hope this helps,
Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top