Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Ajax "mind reader" script

Posted on 2014-01-22
Medium Priority
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.
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!
Question by:Rich Rumble
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
LVL 53

Accepted Solution

Scott Fell,  EE MVE earned 2000 total points
ID: 39800486
If what you are after now is a proof of concept, that has been done via jquery for one.

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.
LVL 53

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
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 but I have no idea what I'm doing, and just break the scripts beyond repair.
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

LVL 53

Expert Comment

by:Scott Fell, EE MVE
ID: 39800597

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.
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!
LVL 53

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?
LVL 58

Expert Comment

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.
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.
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.
LVL 38

Author Comment

by:Rich Rumble
ID: 39836955
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.

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

722 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