سؤال

I'm working with the autocomplete jQuery plugin, but I have faced two main problems.

  1. Calling a function within the autocomplete function
  2. Getting the value of textbox to pass with function

Html

<input id="txtDemo" type="text" />

Js

$("#txtDemo").autocomplete({
   source: availableTags
});

This is my function, Value is value of textbox

function Demo (value)
{
//code for getting value from code behind in the form of array
}
هل كانت مفيدة؟

المحلول

You can add an event handler like this

$('#txtDemo').on('change', function(){
 var value = $(this).val();
 Demo (value); //pass the value as paramter
});

//Handle it here
function Demo (value) {
 //code for getting value from code behind in the form of array
}

From your comments: Possible using select

select( event, ui )Type: autocompleteselect

Triggered when an item is selected from the menu. The default action is to replace the text field's value with the value of the selected item.

$("#txtDemo").autocomplete({   
   source: availableTags,
   select: function( event, ui ) {
            demo(ui.item.value);          
      }

});

Here is sample working fiddle

Hope you can understand.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top