473,396 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

AutoComplete <Textarea>

58
Hi frnds,
I have got a strange requirement,i.e i have to make a <Textarea>
with AutoComplete attribute.so that it il suggest the user with a list of
previously entered values.

Is thr any way to achieve this using javascript or with AJAX???
It il be great,if i am given with some samples.



Thanks in advance,
sundar
Oct 9 '07 #1
4 7348
numberwhun
3,509 Expert Mod 2GB
Hi frnds,
I have got a strange requirement,i.e i have to make a <Textarea>
with AutoComplete attribute.so that it il suggest the user with a list of
previously entered values.

Is thr any way to achieve this using javascript or with AJAX???
It il be great,if i am given with some samples.



Thanks in advance,
sundar
This isn't something that HTML or CSS can do for you (that I know of), unless there is some new advancement.

You will probably have to code that in a language such as Perl, PHP, or Python.

Also, what are you trying to auto complete? Email addresses? Dates?
Oct 9 '07 #2
gsuns82
58
This isn't something that HTML or CSS can do for you (that I know of), unless there is some new advancement.

You will probably have to code that in a language such as Perl, PHP, or Python.

Also, what are you trying to auto complete? Email addresses? Dates?
its a list of descriptions entered by user during previous visit.
regards,
sundar
Oct 9 '07 #3
numberwhun
3,509 Expert Mod 2GB
its a list of descriptions entered by user during previous visit.
regards,
sundar
I think you would have to either rely on the system the user is using to offer the suggestions once they start typing (happens today when I fill out forms in my Firefox browser) or you would have to code for it.

Regards,

Jeff
Oct 9 '07 #4
You can absolutely do this with Javascript (and/or AJAX). If it's a large number of possible autoComplete entries you'll need to use AJAX for speed reasons, but for shorter lists of autoComplete possibilities you can just use a javascript array. The process consists of four basic components:

1. Detect current carat position: See http://www.csie.ntu.edu.tw/~b88039/h...lib/caret.html . Basically, onKeyPress or onKeyDown o(and onFocus), ask for the cursor position.

2. Get the active word: Using the carat position, and the textarea value (str):

Expand|Select|Wrap|Line Numbers
  1. var stringToCursor = str.substring(0, caratPosition);
  2. var start = (stringToCursor.lastIndexOf(" ") + 1); //find where the word starts
  3. //correct for line breaks (so it works on words seperated by spaces AND line breaks
  4.     if(start < stringToCursor.lastIndexOf('\n')){start = stringToCursor.lastIndexOf('\n') + 1;};
  5. var activeWord = str.substring(start, caratPosition);
3. Find Matches: Compare the active word against a javascript array or a database (ajax) to see if it matches the begining of any autoComplete words.

4. Autocomplete: Have the aforementioned function automatically replace the active word or create a popup with suggestions which can replace the word using methods similar to step 2 to find the original word fragment and replace it with the new autoCompletion word at the carat (and you'll probably want to reset the carat at the end of the inserted entry (using range.move() or setSelectionRange() depending on browser).
Nov 5 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Augustus | last post by:
Hiya, I have a form with a <textarea></textarea> to receive user input. This input is then stored in a database and sent by fax... I need to be able to remove the carriage returns (enter...
4
by: Dennis Allen | last post by:
Hi. I hope someone here can help. I'm webmaster for a local astronomy club. Just went over our web site. Have validated every htm file on the site except:...
2
by: Jonathan Taub | last post by:
This may seem a stupid question. I've got a <textarea> element: .... <td> List of items: <textarea> 1. Apple 2. Orange 3. Box
16
by: Martin Trautmann | last post by:
Hi all, I just had a problem where Mozilla 1.6 did not accept a XHTML 1.0 page that contained <p><textarea cols="50" name="prod_prob_description" rows="4" /></p> It did not accept the end...
11
by: Les Paul | last post by:
I'm trying to design an HTML page that can edit itself. In essence, it's just like a Wiki page, but my own very simple version. It's a page full of plain old HTML content, and then at the bottom,...
3
by: Jarek Mielcarek | last post by:
hi all, in xml file I have some fields which are source for <textarea> element. I'd like to transform this file using xslt and set the rows property of <textarea> depend of lines in some source...
8
by: ASP Yaboh | last post by:
I have an ArrayList of data gathered from a database. I want to create a web page from this data by creating a <table>, each cell in each row displays the appropriate data. One of those cells in...
6
by: Tony | last post by:
The w3schools HTML tag reference for <textarea> http://www.w3schools.com/tags/tag_textarea.asp says that the attributes 'cols' and 'rows' are REQUIRED attributes for the textarea tag. Looking at...
3
by: FunkHouse9 | last post by:
I'm working on a form to collect data in a textarea which and am trying to keep returns and spaces. I have a couple of functions that I Frankensteined together to replace returns with <br> and to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.