Advertisement
5ally

[Stack Overflow #49040586] SCRIPT #1 and SCRIPT #2

Mar 1st, 2018
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.78 KB | None | 0 0
  1. The original JS scripts as mentioned on Stack Overflow <https://stackoverflow.com/q/49040586/9217760>.
  2.  
  3. [SCRIPT #1]
  4. /* Auto Suggestion */
  5. /*function insertAfter(newNode, referenceNode) {
  6. referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
  7. }
  8.  
  9. var searchbar = document.getElementById("search_keywords");
  10. document.getElementById("search_keywords").onkeyup= function() {
  11. showResult(this.value);
  12. }
  13.  
  14. var livesearch = document.createElement("div");
  15. livesearch.id = "livesearch";
  16. insertAfter(livesearch, searchbar);*/
  17. /* End of Auto Suggestion */
  18.  
  19. [SCRIPT #2]
  20. <script>
  21. function showResult(str) {
  22. //Get category selection box
  23. var categoryBar = document.getElementById("search_categories");
  24.  
  25. //Doctor
  26. if(categoryBar.options[categoryBar.selectedIndex].value == 88){
  27. if (str.length==0) {
  28. document.getElementById("livesearch").innerHTML="";
  29. document.getElementById("livesearch").style.border="0px";
  30. return;
  31. }
  32. if (window.XMLHttpRequest) {
  33. // code for IE7+, Firefox, Chrome, Opera, Safari
  34. xmlhttp=new XMLHttpRequest();
  35. } else { // code for IE6, IE5
  36. xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  37. }
  38. xmlhttp.onreadystatechange=function() {
  39. if (this.readyState==4 && this.status==200) {
  40. document.getElementById("livesearch").innerHTML=this.responseText;
  41. document.getElementById("livesearch").style.border="1px solid #A5ACB2";
  42. }
  43. }
  44. xmlhttp.open("GET","livesearch_Doctor.php?q="+str,true);
  45. xmlhttp.send();
  46. }
  47. //Lawyer
  48. else if(categoryBar.options[categoryBar.selectedIndex].value == 89){
  49. if (str.length==0) {
  50. document.getElementById("livesearch").innerHTML="";
  51. document.getElementById("livesearch").style.border="0px";
  52. return;
  53. }
  54. if (window.XMLHttpRequest) {
  55. // code for IE7+, Firefox, Chrome, Opera, Safari
  56. xmlhttp=new XMLHttpRequest();
  57. } else { // code for IE6, IE5
  58. xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  59. }
  60. xmlhttp.onreadystatechange=function() {
  61. if (this.readyState==4 && this.status==200) {
  62. document.getElementById("livesearch").innerHTML=this.responseText;
  63. document.getElementById("livesearch").style.border="1px solid #A5ACB2";
  64. }
  65. }
  66. xmlhttp.open("GET","livesearch_Lawyer.php?q="+str,true);
  67. xmlhttp.send();
  68. }
  69. //Mortgage
  70. else if(categoryBar.options[categoryBar.selectedIndex].value == 91){
  71. if (str.length==0) {
  72. document.getElementById("livesearch").innerHTML="";
  73. document.getElementById("livesearch").style.border="0px";
  74. return;
  75. }
  76. if (window.XMLHttpRequest) {
  77. // code for IE7+, Firefox, Chrome, Opera, Safari
  78. xmlhttp=new XMLHttpRequest();
  79. } else { // code for IE6, IE5
  80. xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  81. }
  82. xmlhttp.onreadystatechange=function() {
  83. if (this.readyState==4 && this.status==200) {
  84. document.getElementById("livesearch").innerHTML=this.responseText;
  85. document.getElementById("livesearch").style.border="1px solid #A5ACB2";
  86. }
  87. }
  88. xmlhttp.open("GET","livesearch_Mortgage.php?q="+str,true);
  89. xmlhttp.send();
  90. }
  91. //Realtor
  92. else if(categoryBar.options[categoryBar.selectedIndex].value == 90){
  93. if (str.length==0) {
  94. document.getElementById("livesearch").innerHTML="";
  95. document.getElementById("livesearch").style.border="0px";
  96. return;
  97. }
  98. if (window.XMLHttpRequest) {
  99. // code for IE7+, Firefox, Chrome, Opera, Safari
  100. xmlhttp=new XMLHttpRequest();
  101. } else { // code for IE6, IE5
  102. xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  103. }
  104. xmlhttp.onreadystatechange=function() {
  105. if (this.readyState==4 && this.status==200) {
  106. document.getElementById("livesearch").innerHTML=this.responseText;
  107. document.getElementById("livesearch").style.border="1px solid #A5ACB2";
  108. }
  109. }
  110. xmlhttp.open("GET","livesearch_Realtor.php?q="+str,true);
  111. xmlhttp.send();
  112. }
  113. //All categories
  114. else{
  115. if (str.length==0) {
  116. document.getElementById("livesearch").innerHTML="";
  117. document.getElementById("livesearch").style.border="0px";
  118. return;
  119. }
  120. if (window.XMLHttpRequest) {
  121. // code for IE7+, Firefox, Chrome, Opera, Safari
  122. xmlhttp=new XMLHttpRequest();
  123. } else { // code for IE6, IE5
  124. xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  125. }
  126. xmlhttp.onreadystatechange=function() {
  127. if (this.readyState==4 && this.status==200) {
  128. document.getElementById("livesearch").innerHTML=this.responseText;
  129. document.getElementById("livesearch").style.border="1px solid #A5ACB2";
  130. }
  131. }
  132. xmlhttp.open("GET","livesearch.php?q="+str,true);
  133. xmlhttp.send();
  134. }
  135. }
  136. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement