Weird Thoughts From Eric's Head

Tags - Categories : All | AJAX | BUSINESS | PERSONAL | PROGRAMMING | BOOK REVIEW

Brake Joke
One day this mechanic was working late under a car and some brake fluid dripped into his mouth. "Wow! That stuff isn't too bad tasting," he thought.

The next day he told his buddy about tasting the brake fluid. "Not bad," he said. "Think I'll have a little more today." His friend got a little concerned but didn't say anything.

The following day the mechanic told his friend about drinking a cup full of the brake fluid. "Great stuff! Think I'll have some more today." And so he did.

A few days later the mechanic was up to a bottle a day, and told his friend, "This brake fluid is really great stuff." His friend was now really worried. "You know that brake fluid is poison and really bad for you. You better stop drinking that stuff."

"Hey, no problem," the mechanic replied. "I can stop any time."

Auto Complete JavaScript
I have been working on an auto complete JavaScript function. It is still in the testing phase, but it works with the major browsers that I tested so far.

The code creates a list of options from an array. How the matches are made can be adjusted to find text anywhere in a string or the exact say way the user wants it. You can also ignore case too.

There will be more options added to it in the future.

You can read more about it and download the codehere: AutoComplete Type Ahead Example

If you want to see more options, add a comment here.

Eric Pascarello
Moderator of HTML/JavaScript at www.JavaRanch.com
Author of: JavaScript: Your Visual Blueprint for Dynamic Web Pages


Pressing enter submits the forms instead of selecting the drop down option (this occurs in IE and Safari). Unless this is fixed, the only advantage of this script is to show the user what they *can* type.
The default behavior of a form with one Textbox is to submit when the enter key is pressed.
The default behavior doesn't make sense in this context because it submits a blank form and prevents the user from selecting the option unless the mouse is used. As a user, if I'm presented with a drop down box, I expect to be able to select it in some manner instead of submitting a blank form.
The easy solution is just add another text field to the page. It cancels the deafult action of the enter key since there is more than 1 field. Set the display to hide the element.
<input type="text" name="txtIgnore" style="display:none;">
There is another method of using the onsubmit handler, but is is messy.
Eric


Add a comment

Title
Body
HTML : b, i, blockquote, br, p, pre, a href="", ul, ol, li
Math Quiz 6 + 6 = (Helps stop blog spam)
Name
E-mail address
Website
Remember me Yes  No 

E-mail addresses are not publicly displayed, so please only leave your e-mail address if you would like to be notified when new comments are added to this blog entry (you can opt-out later).

TrackBack to http://radio.javaranch.com/pascarello/addTrackBack.action?entry=1103646787000