最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

autocomplete - Prompt with hints in Javascript - Stack Overflow

programmeradmin2浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论