/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] onchange text and select box

Basically what I am wanting to happen is that when I type a letter in a textbox that it immediately finds the first option in a select(multiple) box that starts with the same character. then if they type a second letter, it find the first option in the select box that starts with those two characters, etc.

Thanks for any help. I’ve tried looking up stuff for linking these concepts together, but I can’t really find any.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Arty_EffemAug 09.2007 — Basically what I am wanting to happen is that when I type a letter in a textbox that it immediately finds the first option in a select(multiple) box that starts with the same character. then if they type a second letter, it find the first option in the select box that starts with those two characters, etc.[/QUOTE]
Try this:[CODE]<html>
<head>
<title>Select Box Matches Text Input</title>
</head>
<body>
<form>
<select name='s1'>
<option value='0'>========
<option value='1'>Aardvark
<option value='2'>Anaconda
<option value='3'>Antelope
<option value='4'>Anteater
<option value='5'>12
<option value='6'>123
<option value='7'>1234
<option value='8'>Bear
<option value='9'>Buffalo
<option value='A'>Bull
<option value='B'>Bullock
</select>
<input type=text size='15' onkeyup='selectFromText(this.value,this.form.s1)'>
</form>

<script type='text/javascript' hex='53747564656E742043484541544544'>

function selectFromText(entry, box)
{
var re=new RegExp('^'+entry,'i'), m;

for(var i=0, match={pos:0, best:-1}; i<box.options.length; i++)
if( (m=box.options[i].text.match(re)) && m.length > match.best )
{
match.best=m.length;
match.pos=i;
}

box.selectedIndex=match.pos;
}

</script>
</body>
</html>
[/CODE]
Copy linkTweet thisAlerts:
@maiku_no_jutsuauthorAug 09.2007 — thanks much...exactly what i was lookin for ?
×

Success!

Help @maiku_no_jutsu spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...