/    Sign up×
Community /Pin to ProfileBookmark

Auto Suggest Textboxes

I have read and used the code of Nicholas C. Zakas for an auto suggest textbox from his 3 part series of articles ([url]http://www.webreference.com/programming/javascript/ncz/)[/url]. I have used the code from Example 3b.

However, I want to be able to use two auto suggest fields on the one form, each reading data from two separate sources.

Does anyone know of a way that I could modify code slightly in order to be able to do this

Cormac

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@intriviousAug 26.2006 — Link does not seem to work for me.
Copy linkTweet thisAlerts:
@championcauthorAug 26.2006 — Take the bracket off the end of the URL


C
Copy linkTweet thisAlerts:
@intriviousAug 26.2006 — If I understand what you are asking, all you would need to do is add another line to the onload() function and another text field.

Something like this (just taken from his example):
[CODE]
<html>
<head>
<title>Autosuggest Example 1</title>
<script type="text/javascript" src="autosuggest1.js"></script>
<script type="text/javascript" src="suggestions1.js"></script>
<script type="text/javascript">
window.onload = function () {
var oTextbox = new AutoSuggestControl(document.getElementById("txt1"), new StateSuggestions());

var oTextbox2 = new AutoSuggestControl(document.getElementById("txt2"), new CitySuggestions());

}
</script>

</head>

<body>
<p>Try it for yourself:</p>
<p>State:<input type="text" id="txt1" /></p>
<p>City:<input type="text" id="txt2" /></p>
</body>
</html>
[/CODE]


As long as the second text box id corresponds to the second instantiation of the autoSuggest and you provide another function in the javascript for your second source, it should be fine.

Say you wanted to do states for one box, and cities another. You would need to make the CitySuggestions().

like this:
[CODE]

function CitySuggestions() {

this.cities = [
"city1", "city2", ....
];

}

[/CODE]


Is this what you are looking for?
Copy linkTweet thisAlerts:
@championcauthorAug 26.2006 — That's exactly it

Many thanks


Cormac
Copy linkTweet thisAlerts:
@championcauthorAug 27.2006 — I have another followon problem which is related. When I get my dropdown list, I can use my arrows to scroll up or down the list but when I press enter to select my choice from the list, my form is then posted.

Is there any way that the value can be picked into the textbox allowing for the next form item to be filled in


C
×

Success!

Help @championc 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.17,
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,
)...