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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:11:57+00:00 2026-06-10T07:11:57+00:00

I am using this autosuggest plugin: http://aehlke.github.com/tag-it/ I am getting an array of items

  • 0

I am using this autosuggest plugin: http://aehlke.github.com/tag-it/

I am getting an array of items from a database (right now just a plain Array). The list includes ID and Title. When I submit my form I would like to get both the ID and Title. Right now I only able to get Title. I want to get both values, so that new References (ID=0) can be created, and existing ones can just be inserted without any database lookup.

This is my code.

Codebehind for the book.aspx – book.aspx.cs:

    ...

    protected void btnSave_Click(object sender, EventArgs e)
    {
        Response.Write(txtReferences.Text); // this contains Titles, but I would like both values.
    }

    public class Reference
    {
        public string Title;
        public int ID;
    }

    [WebMethod]
    public static Array GetReferences(string title)
    {
        // this will be replaced by lookup in database.
        List<Reference> References = new List<Reference>{
            new Reference{ID=1, Title="My ref 1"},
            new Reference{ID=2, Title="Ref ref 2"},
            new Reference{ID=3, Title="Blah ref 3"},
            new Reference{ID=0, Title=title} // for new tags set ID 0 to indicate that this should be created in db
        };

        return References.ToArray();
    }
    ....

This is my current script:

<script type="text/javascript">
$(document).ready(function () {
    var failure = function (result) {
        alert(result.status + " " + result.statusText);
    }

        var ref = $("#<%=txtReferences.ClientID %>");
    ref.tagit({
        allowSpaces: true,
        removeConfirmation: true,
        tagSource: function (title, showChoices) {
            var params = '{"title":"' + title.term + '"}';
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                error: failure,
                url: "book.aspx/GetReferences",
                data: params,
                success: function (data) {
                    var assigned = ref.tagit("assignedTags");
                    var filtered = [];
                    for (var i = 0; i < data.d.length; i++) {
                        if ($.inArray(data.d[i].Title, assigned) == -1) { filtered.push(data.d[i].Title); }
                    }
                    showChoices(filtered);
                }
            });
        }
    });
});
</script>

And of course I have a textbox on the book.aspx page:

<asp:TextBox ID="txtReferences" runat="server" />

Any help is welcome. Thanks.

  • 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-10T07:11:58+00:00Added an answer on June 10, 2026 at 7:11 am

    After looking at tag-it docs and sources, I’m afraid this plugin doesn’t support anything other than simple strings as tags, so if you want to have more information sent back and forth you’ll have to do it yourself. Assuming the Title attribute is unique (i.e. there are no two tags with the same Title but different IDs) it shouldn’t be hard though…

    The first thing you need is, on retrieval, map Title to ID somewhere:

    var ids = {}
    ...
                    for (var i = 0; i < data.d.length; i++) {
                        ids[data.d[i].Title] = data.d[i].ID;
                        if ($.inArray(data.d[i].Title, assigned) == -1) { ... }
                    }
    

    Now you have many options. My suggestion would be using a hidden field, updated every time a tag is added or removed:

    function updateHidden() {
        var chosenTags = $.map(ref.tagit("assignedTags"), function(tag) {
            return { Title:tag, ID:(ids[tag] || 0) }; // If the tag is new, use 0 as the ID
        });
        $("#<%=yourHiddenField.ClientID %>").val(JSON.stringify(chosenTags));
    }
    ...
    ref.tagit({
       ...
       onTagAdded:updateHidden,
       onTagRemoved:updateHidden
    }
    

    (Note: I suggested JSON, but you can use whatever format is more convenient for your server to handle)

    protected void btnSave_Click(object sender, EventArgs e)
    {
        Response.Write(yourHiddenField.Text); // this contains both values, encoded in JSON format.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I using this plugin http://code.drewwilson.com/entry/autosuggest-jquery-plugin While typing MAS there is no data matched, so
I am using this http://code.drewwilson.com/entry/autosuggest-jquery-plugin Here is my html <h1>Category : </h1> &nbsp;<input type=text
I am currently using - http://code.drewwilson.com/entry/autosuggest-jquery-plugin for an autosuggest on my site. I have
Using this page, http://developer.android.com/sdk/compatibility-library.html , I have installed the Android Support Package, added a
Using this tutorial: http://www.c-sharpcorner.com/uploadfile/UrmimalaPal/creating-a-windows-phone-7-application-consuming-data-using-a-wcf-service/ I have created sample/hello world application on the windows phone
I'm using this jQuery AutoSuggest Plugin. It's pretty well documented, but there is a
$select = $this->_db->select()->from($this->_name,array(id,fullname,username,email))->where(fullname LIKE '$query%'); I am using this SQL statement currently to power
Using this railscast http://railscasts.com/episodes/127-rake-in-background?autoplay=true as an example/inspiration (i.e. I'm not trying to implement the
I want to do some autosuggest for my text field, using this plugin AutoSuggest
Using this I successfully able to use qooxdoo to retrive data from my database

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.