I use this autosuggest plugin: http://aehlke.github.com/tag-it/
I get an array of elements from the database (now just a simple array). The list includes an identifier and a name. When I submit my form, I would like to get both an identifier and a name. Right now I can get a Title. I want to get both values so that new links can be created (ID = 0), and existing ones can simply be inserted without searching the database.
This is my code.
Codebehind for book.aspx - book.aspx.cs:
... protected void btnSave_Click(object sender, EventArgs e) { Response.Write(txtReferences.Text);
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 text box on the book.aspx page:
<asp:TextBox ID="txtReferences" runat="server" />
Any help is appreciated. Thanks.
source share