Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript_howto thread: SV: Regular expression match on a select field in real time (ignore my previous e-mail)


Message #1 by "Robert Nyman" <robert.nyman@c...> on Wed, 4 Dec 2002 19:12:44 +0100
Sorry, here's the correct code:

<html>
<head>
	<title>Find name</title>

<script language=3D"JavaScript" type=3D"text/javascript">
<!--
	var arrAllNamesOptions =3D new Array();
	window.onload =3D function (){
=09
document.forms["theForm"].elements["inputField"].focus();
		arrAllNamesOptions =3D
document.forms["theForm"].elements["allNamesSelect"].options;
    }
	function findName(searchText){
		for(var i=3D0; i<arrAllNamesOptions.length; i++){
=09
if(arrAllNamesOptions[i].text.toLowerCase().indexOf(searchText.toLowerCa
se()) =3D=3D 0){
				arrAllNamesOptions[i].selected =3D true;
				break;
			}
			else arrAllNamesOptions[0].selected =3D true;
		}
    }	=09
//-->
</script>

</head>

<body>

<div align=3D"center">
	<form name=3D"theForm" onSubmit=3D"return false">
		<table border=3D"0" cellspacing=3D"2" cellpadding=3D"2">
			<tr>
				<td><input type=3D"text" name=3D"inputField"
value=3D"" size=3D"50" onKeyUp=3D"findName(this.value)"/></td>
			</tr>
			<tr>
				<td>
					<select id=3D"allNamesSelect"
size=3D"10">
						<option> No match found
</option>
						<option>Anders</option>
						<option>Bj=F6rn</option>
						<option>Dan</option>
						<option>Daniel</option>
						<option>Erik</option>
						<option>Gunnar</option>
						<option>Johanna</option>

						<option>Per</option>
						<option>Robert</option>

						<option>Sara</option>
						<option>Tony</option>
						<option>Wictor</option>
					</select>
				</td>
			</tr>
		</table>			=09
	</form>
</div>

</body>
</html>


/Robert



-----Ursprungligt meddelande-----
Fr=E5n: Richard York [mailto:ryork@q...]
Skickat: den 4 december 2002 17:31
Till: JavaScript HowTo
=C4mne: [javascript_howto] Regular expression match on a select field in
real time


Hello,
I was wondering if anyone had any ideas as to how to do a regular
expression match on a select field in real time. 

Here is my project...
I would like a user to be able to type in a few letters in an HTML text
input field and have the select field scroll automatically to matching
values as the user is inputing data, marking that data as selected.  I
would like this to happen in real time, without the use of a submit
button.

Many thanks in advance for any thoughts on this!
: )
Rich




  Return to Index