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

  • Home
  • SEARCH
  • 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 6953703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:30:48+00:00 2026-05-27T14:30:48+00:00

I built an auto-complete function for my website that queries a database for results.

  • 0

I built an auto-complete function for my website that queries a database for results. I currently can get the results, make them into hyperlinks, and dynamically add them to the page. Once in a while I get results that are very long (40-50 characters) and I want to cut them down to 20 characters or less. Here is my current code:

$.ajax({
    type: "POST",
    contentType: "application/json; charset=utf-8",
    url: "autoCompleter2.asmx/GetDatabaseName",
    data: '{"prefixText":"' + $('#tags').val() + '"}',
    dataType: "json",
    success: function(data) {
        $(data.d).each(function(index, value) {
            $("<a />").attr("href", "http://wms.pc.factset.com/sql_database.aspx?name=" + value).appendTo("#databaseHolder").text(value).after("<br />");
        });
    },
});

I have searched all over the internet but I cannot find how to take my “value” variable and cut it into a 20 character sub string. I have seen code like:

$(value).text().substring(0, 2);

but nothing works. Any help would be amazing.

  • 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-05-27T14:30:49+00:00Added an answer on May 27, 2026 at 2:30 pm
    if (value.length > 20) {
        value = value.substr(0, 20);
    }
    

    This assumes that value is a sting.

    Here is a demo: http://jsfiddle.net/hEjxB/

    If value is a DOM element then you can do this:

    var $value = $(value),
        text   = $value.text();
    if (text.length > 20) {
        $value.text(text.substr(0, 20);
    }
    

    Here is a demo: http://jsfiddle.net/hEjxB/1/

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

Sidebar

Related Questions

I just found out that the jQueryUI now has it's own built-in auto-complete combo
I can't get Netbeans to auto-complete my selectors for JQuery, example: <a id=hello href=#>Hello</a>
Does C# has a built-in auto complete textbox which we can drag and drop
When I use Merb's built in console, I get tab auto-completion similar to a
I want to store a set of integers that get auto incremented at build
Is their any jQuery plug-in for auto complete that allows our own styling? Every
I currently have an Entity Framework model that collects data from a legacy database
I have specific built in functions where admins can execute through a website. For
Which built in (if any) tool can I use to determine the allocation unit
I built an application which displays the records from database in the window and

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.