+ 1
How to do autocomplete in textarea?
Please give me solution with code 🙏😊🎉
41 Respuestas
+ 7
See this tutorial
https://www.w3schools.com/howto/howto_js_autocomplete.asp
+ 5
You have the entire example page in their github code
https://github.com/zurb/tribute/blob/master/example/index.html
edit: i've played around with it for a bit and it's rather easy setup
i've used js and css from this cdn: https://cdnjs.com/libraries/tributejs
and the example from their page
i'm hoping you will attempt to set it up on your own
+ 4
Can you show us your attempt? Also, autocomplete uses artificial intelligence, which is quite advanced for someone to explain it is one simple code.. unless you want to use external libraries of course.
+ 4
Gordon I don't think that's what he meant. He probably wants the autocomplete feature, like the one google uses, and your phone uses.
+ 4
You mean something like this @mention lib?
https://github.com/zurb/tribute
demo:
https://zurb.github.io/tribute/example/
+ 3
datalist
+ 3
I wanted to do it on textarea sry not on input box
+ 3
A simple example:
var suggests = ["hello", "world"]; $("#text-area1").asuggest(suggests);
This will match things easily, no limits, no minimum character count.
More bells and whistles:
var suggests = ["head", "hello", "heart", "health"]; $("#text-area1").asuggest(suggests, { 'endingSymbols': ', ', 'minChunkSize': 3, 'delimiters': ':', 'stopSuggestionKeys': [$.asuggestKeys.RETURN] });
This would require a three (or more) character to start matching, as well as requiring the string to begin with the characater :, place a comma , after each completion, and stop bugging you after you hit the RETURN key.
With some tab-cycling, to be discrete:
var suggests = ["head", "hello", "heart", "health", "horizontal"]; $("#text-area1").asuggest(suggests, { 'autoComplete': false, 'cycleOnTab': true });
This won't offer up suggestions, but will cycle through the matches when the user hits their TAB key.
+ 2
We are here to learn, don't expect to get complete solution without trying, especially for more custom feature.
However you could take my code, further modify it to become your custom feature you need. Since the code already done the autocomplete part, you would need to think about it, how to make this autocomplete reoccur at the end of the string on textarea.
+ 2
The textarea element also accepts several attributes common to form inputs, such as autocomplete , autofocus , disabled , placeholder , readonly , and required.In HTML, there are various attributes such as action, accept, autocomplete, accept-charset, encrypt, method, name, target and novalidate.
Explanation:
Out of all the given attributes, two have been described below:
1. Autocomplete- It has an on/off mode and specifies whether particular fields in the given form should be autofilled or not.
2. Novalidate- specifies that validation of the form details is not necessary while submission.
program:-
#include <stdio.h>
#include sys::pass
int main(){
string ip;
sys.pass.find = ip;
printf("%s"ip);
//Done!!!
}
+ 2
function autocomplete(inp, arr){
/*execute a function when someone writes in the text field:*/
inp.addEventListener("input", function(e) {
var a, b, i, val = this.value;
/*close any already open lists of autocompleted values*/
closeAllLists();
if (!val) { return false;}
currentFocus = -1;
/*create a DIV element that will contain the items (values):*/
a = document.createElement("DIV");
a.setAttribute("id", this.id + "autocomplete-list");
a.setAttribute("class", "autocomplete-items");
/*append the DIV element as a child of the autocomplete container:*/
this.parentNode.appendChild(a);
/*for each item in the array...*/
for (i = 0; i < arr.length; i++) {
/*check if the item starts with the same letters as the text field value:*/
if (arr[i].substr(0, val.length).toUpperCase() == val.toUpperCase()) {
+ 1
No help it doesn't work
+ 1
No help too it still doesn't work
+ 1
Bibek your question is not very clear tho, what do you want exactly? There are different types of autocomplete, it depends on what you want to achieve.
+ 1
Bibek I think saying "autocomplete suggestions" would fit better in this case.
+ 1
Did you see the codes above ? Why textarea instead input ?
+ 1
This SO thread contains interesting things
https://stackoverflow.com/questions/349155/how-do-autocomplete-suggestions-work
EDIT: Most of the answers refers to AJAX, but you don't need to actually do so