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 7918723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:36:21+00:00 2026-06-03T15:36:21+00:00

I am fairly new to jQuery and JSON and have run into a problem

  • 0

I am fairly new to jQuery and JSON and have run into a problem I haven’t been able to solve. I have a textbox that I would like a user to start typing a person’s name and when he/she selects the name, it autopopulates another textbox with their email address.

My code is as follows. Any help getting this to work would be greatly appreciated. Thanks so much in advance!

Markup

<input type="text" id="person_name" class="required" />
<input type="text" id="person_email_address" class="required email" />

jQuery

$( "input#person_name" ).autocomplete({
    source: "/autoComplete.aspx",
    dataType: "json",
    minLength: 1,
    select: function( event, ui ) {
        //set email textbox to the email field of the selected item.
    }
});

autoComplete.aspx.cs

protected void Page_Load(object sender, EventArgs e)
{
    string term = Request.QueryString["term"];

    if (!string.IsNullOrEmpty(term))
    {
        string sql = string.Format("select * from users where first_name like '%{0}%' or last_name like '%{0}%'", term);

        DataTable dt = GetTable(sql);

        foreach (DataRow dr in dt.Rows)
        {
            string name = dr["first_name"].ToString() + dr["last_name"].ToString();
            string email = dr["email"].ToString();
        }

        Response.ContentType = "application/json";
        Response.Write("what goes here so i can access both email and name in the select function?");
    }
}
  • 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-03T15:36:22+00:00Added an answer on June 3, 2026 at 3:36 pm

    Use something like this in your code-behind:

    var items = dt.AsEnumerable().Select(
        dr => new 
        {
            name = dr["first_name"].ToString() + dr["last_name"].ToString(),
            email = dr["email"].ToString()
        }
    );
    string json = "[" + string.Join(",", 
            items.Select(i => 
                "{ id: '" + i.name + "'"
                + ", label: '" + i.name + "'"
                + ", value: '" + i.email + "'"
                + "}"
            )
        ) + "]";
    
    Response.Write(json);
    

    That should get you the correct JSON, with name as the label, and email as the value. Now in the Javascript select callback function, set the email textbox to the correct value:

    select: function( event, ui ) {
        //set email textbox to the email field of the selected item.
        $("#person_email_address") = ui.item.value;
    }
    

    NOTE

    Per comments, the above is invalid without modification. The JSON values have to be wrapped in double quotes.

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

Sidebar

Related Questions

I am fairly new to JQuery API. I have been using mouseover, but I
I am fairly new to jQuery and I have this overlay window that pops
I fairly new to JQuery and perhaps trying to achieve something that might be
I'm fairly new to jQuery and I'm having trouble with an animation that I'd
I'm fairly new to jQuery and I've been looking for a decent free datepicker
I'm fairly new to jquery and working with json, so please bear with me.
I'm fairly new to jquery and struggling with something that should be fairly simple.
(I'm fairly new to jQuery.) I have a traditional HTML form with 3 drop-down
Ok, i'm fairly new to jQuery JSON stuff. I'm trying to access the actions
I am fairly new to jquery and I have a question about updating data

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.