[Javascript] Re: ComboBox
Chris Tifer
christ at saeweb.com
Fri Mar 21 07:58:15 CST 2003
Do as I suggested then where on the onKeyUp event of the <INPUT> element
you take the string and loop through the elements in your <SELECT> looking
for that value.
Here's a simple example you can look at to see what I'm talking about:
<HTML>
<head>
</head>
<form name="Test1">
<input type="text" name="myText" onKeyUp="searchSelect('Test1', 'mySelect',
this.value)">
<br />
<SELECT name="mySelect">
<OPTION VALUE="PostOffice">PostOffice
<OPTION VALUE="GoPostal">GoPostal
<OPTION VALUE="Postman">Postman
</SELECT>
</form>
<script language="Javascript">
function searchSelect(strMyForm, strMyEl, strText){
var objForm = document.forms[strMyForm]
var objEl = objForm.elements[strMyEl]
if(strText.length > 0){
for(var x = 0; x < objEl.options.length; x++){
if(objEl.options[x].value.toLowerCase().indexOf(strText.toLowerCase()) >=
0){
//alert(objEl.options[x].value.indexOf(strText))
objEl.options[x].selected = true
return
}
}
}
}
</script>
</HTML>
----- Original Message -----
From: "andy susanto" <andy78 at centrin.net.id>
To: <javascript at LaTech.edu>
Sent: Friday, March 21, 2003 3:11 AM
Subject: [Javascript] Re: ComboBox
> Hai,
>
> sorry for my question. Because i do not know in javascript name object
> <Select>, so i call that a combobox( because my background is Delphi).
What
> i want is when i type a char i can see that char like <input> and i can
> insert not just a char but i can insert two and more char. example:
>
> <Option>PostOffice</Option>
> <Option>Postman</Option>
>
> when i type "Post" maybe that<select> will focus on PostOffice, when i
type
> a char again "m" <select> will focus on Postman
>
> TIA,
>
> andy
>
>
> > There are no comboboxes in HTML actually unless you want to do
> > some fancy programming or use an Active X component of some
> > sort.
> >
> > But on a SELECT list, if you press a key and that is the first character
> for
> > any of the OPTIONS, it will cycle through those that match.
> >
>
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
More information about the Javascript
mailing list