Advertisement
Guest User

Untitled

a guest
Jul 4th, 2015
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. var $local_source = ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby"];
  2. $("#txtAllowSearch").autocomplete({
  3. source: $local_source
  4. });
  5.  
  6. $('#button').click(function() {
  7. // alert($("#txtAllowSearch").someone_get_id_of_selected_item);
  8. });
  9.  
  10. $('#selector').autocomplete({
  11. source: url,
  12. select: function (event, ui) {
  13. $("#txtAllowSearch").val(ui.item.label); // display the selected text
  14. $("#txtAllowSearchID").val(ui.item.value); // save selected id to hidden input
  15. }
  16. });
  17.  
  18. $('#button').click(function() {
  19. alert($("#txtAllowSearchID").val()); // get the id from the hidden input
  20. });
  21.  
  22. var $local_source = [[0,"c++"], [1,"java"], [2,"php"], [3,"coldfusion"],
  23. [4,"javascript"], [5,"asp"], [6,"ruby"]];
  24.  
  25. var $local_source = [{
  26. value: 1,
  27. label: "c++"
  28. }, {
  29. value: 2,
  30. label: "java"
  31. }, {
  32. value: 3,
  33. label: "php"
  34. }, {
  35. value: 4,
  36. label: "coldfusion"
  37. }, {
  38. value: 5,
  39. label: "javascript"
  40. }, {
  41. value: 6,
  42. label: "asp"
  43. }, {
  44. value: 7,
  45. label: "ruby"
  46. }];
  47.  
  48. $('#sistema_select').autocomplete({
  49.  
  50. minLength: 3,
  51. source: <?php echo $lista_sistemas;?> ,
  52. select: function (event, ui) {
  53. $('#sistema_select').val(ui.item.label); // display the selected text
  54. $('#sistema_select_id').val(ui.item.value); // save selected id to hidden input
  55. return false;
  56. },
  57. change: function( event, ui ) {
  58. $( "#sistema_select_id" ).val( ui.item? ui.item.value : 0 );
  59. }
  60. });
  61.  
  62. var $local_source = [
  63. {value: 1, label: "c++"},
  64. {value: 2, label: "java"}]
  65.  
  66. {"list":[
  67. {"value": 1, "label": "abc"},
  68. {"value": 2, "label": "def"},
  69. {"value": 3, "label": "ghi"}
  70. ]}
  71.  
  72. source: function(request, response) {
  73. $.getJSON("listing.php", {
  74. term: request.term
  75. }, function(data) {
  76. var array = data.error ? [] : $.map(data.list, function(m) {
  77. return {
  78. label: m.label,
  79. value: m.value
  80. };
  81. });
  82. response(array);
  83. });
  84. },
  85. select: function (event, ui) {
  86. $("#autocomplete_field").val(ui.item.label); // display the selected text
  87. $("#field_id").val(ui.item.value); // save selected id to hidden input
  88. return false;
  89. }
  90.  
  91. <script type="text/javascript">
  92. $(function () {
  93. $("#MyTextBox").autocomplete({
  94. source: "MyDataFactory.ashx",
  95. minLength: 2,
  96. select: function (event, ui) {
  97. $('#MyIdTextBox').val(ui.item.id);
  98. return ui.item.label;
  99. }
  100. });
  101. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement