最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

autocomplete - Prompt with hints in Javascript - Stack Overflow

matteradmin6PV0评论

I'd like to get some input from the user:

keywords = prompt("Input keywords separated by mas", "");

I have many various strings stored in an SQLite database that could suggest the user what to type. Let's say you have an array or list of these strings. How would you code this hinting in Javascript? Are there some functions or code snippets for this functionality?

I'd like it to work similarly as here. When you start typing you get hint with possibilities. There is only one disadvantage, that you can't input more strings separated by mas. Here is this feature working with more strings.

Is prompt() function suitable for this purpose? You can use another way of getting user input.

Thank you

I'd like to get some input from the user:

keywords = prompt("Input keywords separated by mas", "");

I have many various strings stored in an SQLite database that could suggest the user what to type. Let's say you have an array or list of these strings. How would you code this hinting in Javascript? Are there some functions or code snippets for this functionality?

I'd like it to work similarly as here. When you start typing you get hint with possibilities. There is only one disadvantage, that you can't input more strings separated by mas. Here is this feature working with more strings.

Is prompt() function suitable for this purpose? You can use another way of getting user input.

Thank you

Share Improve this question asked Mar 30, 2012 at 8:46 xralfxralf 3,33250 gold badges140 silver badges217 bronze badges 1
  • do you want plain javascript or jquery also? – Bogdan Emil Mariesan Commented Mar 30, 2012 at 8:49
Add a ment  | 

2 Answers 2

Reset to default 3

You cannot tweak the native prompt() javascript method.

I know you did not tag with jQuery but would be way easier to use a library to implement such a behavior.

You'll have to build your own dialog system using maybe jQuery UI Dialogs. They have an option to make it modal so the UI is blocked until the dialog is closed.

jQuery UI Dialog will not block javascript execution though like prompt does. You might need to be able to execute code when the dialog is closed. This answer show a way to implement that easily.

Finally, the jQuery UI Autoplete provides an example on how to use it for multiple values in the same input. They use a ma-separator but I guess you could modify the example to work with whitespaces: jQuery UIAutoplete Multiple Values

You can't really use any custom functionality with prompt().

You'd be better off creating an <input type="text"/> and hooking the whole thing up to a button, making the data get submitted whenever a use clicks it, or presses enter. Then code it to fetch an autosugges value whenever the user types in a new character.

You should take a look at jQuery UI's autoplete ponent (it works with multiple strings as an input as well). You would also need to set up a server-side script that will take a possibly inplete string as an input and output a possible list of matches back to the browser.

Post a comment

comment list (0)

  1. No comments so far