Solved

Ajax "mind reader" script

Posted on 2014-01-22
11
345 Views
Last Modified: 2014-04-03
I know next to nothing of coding, but I know how to embed what I'm asking for in html :)
I'd like to use jquery as I have it already in use in the site, but "plain JS" will work too. Can someone create a "mind reader" in ajax. I want what I type (rather the user types) on the form line to appear in the "results" at the bottom of the form. In addition to what was typed, I'd like to put other words next to that result, totally random words from a small list.

If the input was
"the slow turtle"
Below in the results window I'd like the same input, plus 20-30 other "results" derived from a short list.
Results:
the slow turtle       <--top result is "closest match" and what they typed in already
the slow turtle in a box <-- these are some f the "random" words appended to the end
the slow turtle is green
the slow turtle slow
the slow turtle the
the slow turtle turtle
the slow turtled
the slow turtles
the slow turtle the slow turtle
the slow turtle elturt wols eht

No matter what is typed in, it's output on the left (results), and on the right after each key press, some random word is appended to the right. If possible, I'd like some sort of "text mirroring" in the results. Like if I type in "blue" and "blue eulb" is one of the results, then typing in an extra letter "blues" would result in not seeing that former result at all anymore, but a whole new set (blues ist, blues asdf etc...)

Rules for the results are: After 4 characters are typed, the results "begin" to appear. Each letter added after will result in 20-30 new "results", each result contains everything typed in so far as the top result, and then 20-30 of the other "results" have words appended to them. Some results may just be the top result spelled backwards appended to it, or just doubled (blue eulb|blue blue).

It's part of a CAPTCHA system we're thinking about, but all I need is some proof of concept now and this would get that done for me. The word list will reside in a directory on the server in the same folder as the html page. Just use Lorem Ipsum words for now, see attached.

I hope it's clear enough what I want, makes sense to me but that doesn't mean it make sense :) If straight JS will do, use that, I just thought Jquery is popular and I have it available already too. Let me know what other questions you have I'll be happy to answer!
-rich
words.txt
0
Comment
Question by:Rich Rumble
  • 4
  • 4
11 Comments
 
LVL 52

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 total points
ID: 39800486
If what you are after now is a proof of concept, that has been done via jquery for one. http://jqueryui.com/autocomplete/

You can program to start after n characters are typed.  The other magic as far as what is shown is dependent on the data.  You can  use the data in another file such as json/jsonp or from a database.  

It can search for any part of a word or phrase, just the left side or the right.
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39800494
Just to add, I have also had success with typeahead as I work with bootstrap a lot  http://twitter.github.io/typeahead.js/
0
 
LVL 38

Author Comment

by:Rich Rumble
ID: 39800517
Thanks, but I can't code :) I have no idea how to do this, or use either of those libraries. The first looks closest, and I know it seems like how google or other sites try to predict, but it's not what I'm after. It's outputting what was input, and appending random words, or random manipulations to the end of the words.
It is close to auto-completing, but different. I don't know how to programatically change the JS to do what I described. I've tried various fiddles and auto-completes on http://jsfiddle.net/ but I have no idea what I'm doing, and just break the scripts beyond repair.
-rich
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39800597
richrumble

We are happy to help you, but not write the code for you.   We can give you the start and help solve issues in your code that you do have.  But you are asking for both logic and  programming and this is not the place to get free work.    

>but I have no idea what I'm doing

You will need to hire somebody to do this for you.

fyi, I did try and look at your jsfiddle but it is blank.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 38

Author Comment

by:Rich Rumble
ID: 39800617
I get this help all the time here :) Just not JS, typically VBS/PHP or Perl. I'll wait for another expert, thanks!
-rich
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39800688
>I've tried various fiddles

The fiddle you did point to is empty.  Which one was close?
0
 
LVL 58

Expert Comment

by:Gary
ID: 39800710
Writing a few lines of VB to scan a directory is not the same as writing a full blown autocomplete with many other factors to take into account and program for.
If it is outside of your programming capabilities then you need to hire a programmer.
http://www.freelancer.com/
You are a member here long enough to know this is a two way street and not a gimme, gimme.
It is expecting too much to expect someone to spend hours doing your work for you for no recompense but a B grade.
You asked for proof of concept and Scott gave you the concept with the jQuery autocomplete.
0
 
LVL 38

Author Comment

by:Rich Rumble
ID: 39800884
I link I may have over complicated it...I thought %input + %rand sounded simple enough to a seasoned programmer and wouldn't constitute a whole class or hours of work. I can see it in my head like this:

form_line = %input
if $input =>4 then
<!--(rand is some of the words from a txt file in the local dir, or in an array?-->
echo %input + %rand 1
echo %input + %rand 2
echo %input + %rand 3
echo %input + inverse(%input)
echo %input + %input
echo %input + %rand 5
echo %input + %rand 6
echo %input + %rand 7

It "looks" easy to me, am I over simplifying it? Does that make the task seem like less? I certainly don't want to "get something for free". I thought it sounded "simple enough" is all.
It doesn't have to be "true ajax", just look that way I guess? Each key-press results in new "results" like the above. That is the "ajax" part is each key-press.
-rich
0
 
LVL 38

Author Comment

by:Rich Rumble
ID: 39836955
http://jsfiddle.net/G7UD6/
I'm getting random words on the end of what is typed. I mashed up two other fiddles I found. What it needs are more lines in the textarea, with more random words. That I can't seem to get yet. Again it's echoing the first result, I'd like it to echo 10 or more as well.
It didn't take me too long once I found some code that was working, I just don't know the next function or call to make.
-rich
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now