Advertisement
Guest User

Untitled

a guest
May 3rd, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. ==================
  2. Dependencies
  3. ==================
  4. <!-- Auto Suggestion -->
  5. <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  6.  
  7. <!-- Auto Suggestion js-->
  8. <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
  9.  
  10. ==================
  11. index.php
  12. ==================
  13. //Auto Suggestion
  14. function split( val ) {
  15. return val.split( /,\s*/ );
  16. }
  17. function extractLast( term ) {
  18. return split( term ).pop();
  19. }
  20.  
  21. $( "#id" )
  22. // don't navigate away from the field on tab when selecting an item
  23. .bind( "keydown", function( event ) {
  24. if ( event.keyCode === $.ui.keyCode.TAB &&
  25. $( this ).data( "autocomplete" ).menu.active ) {
  26. event.preventDefault();
  27. }
  28. })
  29. .autocomplete({
  30. source: function( request, response ) {
  31. $.getJSON( "codes/multisuggest.php",{
  32. term: extractLast( request.term )},
  33. function( data ) {
  34. response( $.map( data, function( item ) {
  35. return {
  36. value: item.id,
  37. parentname: item.parentname,
  38. address: item.address,
  39. name: item.name,
  40. mobile: item.mobile,
  41. due: item.due
  42. }
  43. }));
  44. }
  45. );
  46. },
  47. search: function() {
  48. // custom minLength
  49. var term = extractLast(this.value);
  50. if (term.length < 1) {
  51. return false;
  52. }
  53. },
  54. focus: function() {
  55. // prevent value inserted on focus
  56. return false;
  57. },
  58. select: function( event, ui ) {
  59. $('#id').val(ui.item.value);
  60. $('#name').val(ui.item.name);
  61. $('#parentdetail').val(ui.item.parentname+', '+ui.item.address+', Mob- '+ui.item.mobile);
  62. $('#mobile').val(ui.item.mobile);
  63. $('#amount').val(ui.item.due);
  64. $('#div-parentinfo').css('display','block')
  65.  
  66. $('#amount').focus()
  67. /* $('#due_amt').val(ui.item.due)
  68. if (ui.item.problematic!=1){
  69. $('#companyautocomplete').removeClass("ui-autocomplete-error");
  70. document.getElementById('Sendbutton').style.display="block";
  71. } else {
  72. $('#companyautocomplete').addClass("ui-autocomplete-error");
  73. document.getElementById('Sendbutton').style.display="none";
  74. }*/
  75. }
  76. });
  77.  
  78.  
  79. =================
  80. multisuggest.php
  81. =================
  82. <?php
  83. //database configuration
  84. //include("../../require/connection.inc.php");
  85. require_once("../config/config.php");
  86. $dbHost = HOST;
  87. $dbUsername = USER;
  88. $dbPassword = PASS;
  89. $dbName = DB;
  90.  
  91. //connect with the database
  92. $db = new mysqli($dbHost,$dbUsername,$dbPassword,$dbName);
  93. //get search term
  94. $searchTerm = $_GET['term'];
  95.  
  96. //get matched data from skills table
  97. $dataArr = array();
  98. $query = $db->query("SELECT `student_id`, `studentname`, `parentname`, `mobile`, `address`, `due_amt`,`status` FROM `student_due` WHERE `student_id` LIKE '%".$searchTerm."%' LIMIT 0,10");
  99. while ($row = $query->fetch_assoc()) {
  100.  
  101.  
  102. $dataArr = array();
  103. array_push($dataArr,array(
  104. "id"=>strtoupper($row['student_id']),
  105. "name"=>ucwords($row['studentname']),
  106. "parentname"=>ucwords($row['parentname']),
  107. "address"=>ucwords($row['address']),
  108. "due"=>$row['due_amt'],
  109. "mobile"=>$row['mobile'],
  110. )
  111. );
  112. }
  113.  
  114. //return json data
  115. echo json_encode($dataArr);
  116. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement