How to get multiple value from Autocomplete TextBox1 and use it in TextBox2
I have 2 Autocomplete Textbox TextBox1 and TextBox2. On TextBox1 i displayed pid value from my job table. On my job table i have 3 column namely id, pid and diereferenceno.
However the diereferenceno is the same thing as the id no in the die table. what i want is to select pid and diereferenceno though the diereferenceno will not be visible in TextBox1, meaning the pid will autocomplete in TextBox1 but i will use the associated diereferenceno of the pid in Autocomplete Textbox1 to Autocomplete associated diereferenceno in Textbox2.
My Code
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link href="http://code.jquery.com/ui/1.11.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script type="text/javascript">
$(function () {
SearchText();
SearchText3();
});
function SearchText() {
$(".autosuggest").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Order.aspx/GetAutoCompleteData",
data: "{ 'pid': '" + request.term + "'}",
dataType: "json",
success: function (data) {
if (data.d.length > 0) {
response($.map(data.d, function (item) {
return {
label: item.split('/')[0],
val: item.split('/')[1]
}
}));
}
else {
response([{ label: 'No Records Found', val: -1}]);
}
},
error: function (result) {
alert("Error");
}
});
},
select: function (event, ui) {
if (ui.item.val == -1) {
return false;
}
$('[id*=hfPId]').val(ui.item.val);
}
});
}
$(function () {
SearchText31();
});
function SearchText31() {
$(".autosuggest31").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Order.aspx/GetAutoCompleteData31",
data: "{ 'embid': '" + request.term + "', diereferneceno: '" + $(".autosuggest").val() + "'}",
dataType: "json",
success: function (data) {
if (data.d.length > 0) {
response($.map(data.d, function (item) {
return {
label: item.split('/')[0],
val: item.split('/')[1]
}
}));
}
else {
response([{ label: 'No Records Found', val: -1}]);
}
},
error: function (result) {
alert(result.responseText);
}
});
},
select: function (event, ui) {
if (ui.item.val == -1) {
return false;
}
}
});
}
</script>
Please help
[WebMethod]
public static List<string> GetAutoCompleteData(string pid)
{
List<string> result = new List<string>();
using (SqlConnection con = new SqlConnection("Data Source=NERO-SIGBENU\\SQLEXPRESS01;Integrated Security=true;Initial Catalog=arpackaging;"))
{
using (SqlCommand cmd = new SqlCommand("select id,pid from job where pid LIKE '%'+@SearchText+'%'", con))
{
con.Open();
cmd.Parameters.AddWithValue("@SearchText", pid);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
result.Add(string.Format("{0}/{1}", dr["pid"], dr["id"]));
}
return result;
}
}
[WebMethod]
public static List<string> GetAutoCompleteData32(string dieno, string diereferneceno)
{
List<string> result = new List<string>();
using (SqlConnection con = new SqlConnection("Data Source=NERO-SIGBENU\\SQLEXPRESS01;Integrated Security=true;Initial Catalog=arpackaging;"))
{
using (SqlCommand cmd = new SqlCommand("select id,dieno from job_die where id=@diereferneceno ", con))
{
con.Open();
cmd.Parameters.AddWithValue("@SearchText32", dieno);
cmd.Parameters.AddWithValue("@id", diereferneceno);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
result.Add(string.Format("{0}/{1}", dr["dieno"], dr["id"]));
}
return result;
}
}
}