Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prompt with hints in Javascript

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

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

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 commas. 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

like image 316
xralf Avatar asked Mar 30 '12 08:03

xralf


1 Answers

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 Autocomplete provides an example on how to use it for multiple values in the same input. They use a comma-separator but I guess you could modify the example to work with whitespaces: jQuery UIAutocomplete Multiple Values

like image 189
Didier Ghys Avatar answered Sep 25 '22 03:09

Didier Ghys