Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8886375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:32:37+00:00 2026-06-14T21:32:37+00:00

I need help, I am stuck with trying to make the following case scenario

  • 0

I need help, I am stuck with trying to make the following case scenario work:
You have email input field, you type: foo@y – it should pop up autocomplete box, offering yahoo.com (for example).
If you take this suggestion, the end value should become: foo@yahoo.com

I have wrote this code (modified off another jquery UI sample):


        $( "#tags" )
            // don't navigate away from the field on tab when selecting an item
            .bind( "keydown", function( event ) {
                if ( event.keyCode === $.ui.keyCode.TAB &&
                        $( this ).data( "autocomplete" ).menu.active ) {
                    event.preventDefault();
                }
            })
            .autocomplete({
                minLength: 3,
                source: function( request, response ) {
                            var mail_regex = /^([\w.]+)@([\w.]+)$/;
                            var match = mail_regex.exec(request.term);
                            if (match)
                                var matcher = new RegExp( "^" + match[2], "i" );
                            response( $.grep( availableTags, function( item ){
                                return matcher.test( item );
                            }) );
                 },
                focus: function() {
                    // prevent value inserted on focus
                    return false;
                },
                select: function( event, ui ) {
                    var terms = split( this.value );
                    // remove the current input
                    terms.pop();
                    // add the selected item
                    terms.push( ui.item.value );
                    // add placeholder to get the comma-and-space at the end
                    terms.push( "" );
                    this.value = terms.join( ", " );
                    return false;
                }
            });

Full working interactive sample:
http://jsfiddle.net/rRF2s/3/

However, it REPLACES the foo@ with just yahoo.com - I can not for the life of me figure out how to override this behaviour...

Any Javascript/jQuery masters - help please! how to accomplish this goal?
I tried doing: return match[1]+matcher.test( item ), but that does not work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T21:32:39+00:00Added an answer on June 14, 2026 at 9:32 pm

    The select function is assigning the resultant value with this.value =. However it is replacing the input value completely rather than appending it with the drop down value.

    Without a great deal of testing the following, simplified function seems to work as required:

    select: function( event, ui ) {
        this.value = this.value.substring(0, this.value.indexOf('@') + 1) + ui.item.value;
        return false;
    }
    

    This is taking the first part of the already entered value, for example foo@ for the input foo@ya and then adding on the value of the selected item from the drop down.

    You may want to trigger the dropdown when someone enters the @ symbol (seems more intuitive to me) and if so, this function may also need modifying to correctly extract the user entered value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to get my head around to make things work with
Im stuck in my project here and i really need some help! I have
I have little knowledge of java scripting, and need help making my application work.
I need some help with my web service and json call.. stuck trying to
Ok well I need some help because I am plain stuck. I am trying
I'm completely stuck and need your help... I've created a webservice stub with jaxb
I am stuck and in need of a hand. Hope someone can help? Anyone
need help/guide for sql select query, I have 2 table stock and stock_history, in
Need help with a query that I wrote: I have three tables Company id
I'm currently stuck on trying to make a naive algorithm which given a piece

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.