Guest User

Untitled

a guest
Dec 12th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.93 KB | None | 0 0
  1. //For search country function
  2. $("#search-btn").on("click", function ()
  3. {
  4. if(document.getElementById("search").value.length < 3)
  5. {
  6. alert("The characters MUST NOT be less than 3!");
  7. return false;
  8. }
  9.  
  10.  
  11. $("#records").empty();
  12. $(".records").empty();
  13. $('.searchResults').empty();
  14.  
  15. var searchCountry = $("#search").val();
  16.  
  17. $.get(
  18. 'searchCountryRecords.php',
  19. {id: searchCountry}, //left->sql id ,right->script id
  20. function (data)
  21. {
  22. if (!$.trim(data)){
  23. alert("No country with that name is found!");
  24. return false;
  25. }
  26.  
  27. var userRole = "<?php echo $userRole; ?>";
  28.  
  29. var string = "";
  30.  
  31. string += '<table id="tbl_countries" class="table table-bordered table-hover">';
  32. string += '<tr>';
  33. string += '<th>Flag</th>';
  34. string += '<th>Country Name</th>';
  35. string += '<th width=200px>Region</th>';
  36. string += '<th>Surface Area</th>';
  37. string += '<th>Population</th>';
  38. string += '<th width=150px>Independent Year</th>';
  39. string += '<th width=100px>City Details</th>';
  40. if (userRole === "admin")
  41. {
  42. string += '<th width=100px>More Details</th>';
  43. string += '<th width=100px>Update Details</td>';
  44. string += '<th width=100px>Upload Flag</td>';
  45. }
  46. string += '</tr>';
  47.  
  48. /* from result create a string of data and append to the div */
  49. $.each( data, function( key, value )
  50. {
  51. $("#records").empty();
  52. string += "<tr>";
  53. //string += "<td>"+"<img src='data:image/png;base64,base64_encode("+value['image']+")"+"'/>"+"</td>";
  54. string += "<td>"+"<img src='data:image/jpeg;base64', value="+value['image']+">"+"</td>";
  55. string += "<td>"+value['Name']+"</td>";
  56. string += "<td>"+value['Region']+"</td>";
  57. string += "<td>"+value['SurfaceArea']+"</td>";
  58. string += "<td>"+value['Population']+"</td>";
  59. string += "<td>"+value['IndepYear']+"</td>";
  60. string += "<td>"+"<button class='btn btn-block btn-info btn-sm' data-toggle='modal' data-target='#cityModal' id='city_details' name='city_details' type='submit' value='" + value['A3Code'] + "'><span class='glyphicon glyphicon-info-sign'></button>" + "</td>";
  61. if (userRole === "admin")
  62. {
  63. string += "<td>"+"<button class='btn btn-block btn-info btn-sm' data-toggle='modal' data-target='#countryModal' id='more_details' name='country_details' type='submit' value='" + value['A3Code'] + "'><span class='glyphicon glyphicon-info-sign'></button>" + "</td>";
  64. string += "<td>"+"<button class='btn btn-block btn-default btn-sm' data-toggle='modal' data-target='#updateModal' id='update_HOS' name='update_HOS' type='submit' value='" + value['A3Code'] + "'><i class='fa fa-edit'></i></button>" + "</td>";
  65. string += "<td>"+"<button class='btn btn-block btn-default btn-sm' data-toggle='modal' data-target='#uploadModal' id='upload_flag' name='upload_flag' type='submit' value='" + value['A3Code'] + "'><i class='fa fa-flag'></i></button>" + "</td>";
  66. }
  67. string += "</tr>";
  68. });
  69.  
  70. string += '</table>';
  71. $("#records").append(string);
  72. }
  73. );
  74. }); // end of search function
Add Comment
Please, Sign In to add comment