Guest User

Untitled

a guest
Jul 30th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. <html>
  2. <head>
  3. <script src="js/jquery.js" language="javascript"></script>
  4. <style>
  5. ul.submenu{display:none;}
  6.  
  7. </style>
  8. <script type="text/javascript">
  9. //處理摺疊效果的JQ
  10. $(function(){
  11. $(".menu a").click(function(){
  12. var _this=$(this);
  13. if(_this.next("ul").length>0){
  14. _this.html(_this.html()).next().toggle("20000");
  15. return false;
  16. }
  17. });
  18. $("a").focus( function(){
  19. $(this).blur();
  20. });
  21. });
  22. </script>
  23.  
  24. <script type="text/javascript">
  25. //處理AJAX的JS
  26. function showCustomer(str)
  27. {
  28. var xmlhttp;
  29. if (str=="")
  30. {
  31. document.getElementById("txtHint").innerHTML="";
  32. return;
  33. }
  34. if (window.XMLHttpRequest)
  35. {// code for IE7+, Firefox, Chrome, Opera, Safari
  36. xmlhttp=new XMLHttpRequest();
  37. }
  38. else
  39. {// code for IE6, IE5
  40. xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  41. }
  42. xmlhttp.onreadystatechange=function()
  43. {
  44. if (xmlhttp.readyState==4 && xmlhttp.status==200)
  45. {
  46. document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
  47. }
  48. }
  49. //下拉式選單選了以後, 把值塞到另一個dbs.php, 回傳DB中撈出來的資料
  50. //但是這資料很長, 所以想要可以摺疊,
  51. //我以為只要回傳的內容可以搭配上面的摺疊JQ就可以達到折疊的效果
  52. xmlhttp.open("GET","dbs.php?project_id="+str,true);
  53. xmlhttp.send();
  54. }
  55.  
  56. </script>
  57. </head>
  58. <body>
  59.  
  60. //以下產生下拉式選單
  61. <form action="">
  62. <select name="customers" onchange="showCustomer(this.value)">
  63. <option value="">Select a customer:</option>
  64. <?php
  65. $father_proj_name = array();
  66. function preparation()
  67. {
  68. global $father_proj_name;
  69. $prepare_SQL = "SELECT * FROM `projects`";
  70. $prepare_result = mysql_query($prepare_SQL) or die("Query error in preparation father_proj_id");
  71. while($row = mysql_fetch_array($prepare_result))
  72. {
  73. if (is_null($row[parent_id]))
  74. {
  75. $father_proj_name[$row[name]] = $row[id];
  76. }
  77. }
  78. }
  79. //for DB connection
  80. $dbhost = 'localhost';
  81. $dbuser = 'redmine_admin';
  82. $dbpass = 'caswell';
  83. $dbname = 'redmine_test';
  84. $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error with MySQL connection');
  85. mysql_select_db($dbname);
  86. preparation();
  87.  
  88. while (list($key, $val) = each($father_proj_name)) {
  89. echo "<option value="$val">$key</option>";
  90. }
  91. //以上產生下拉式選單
  92. ?>
  93.  
  94. </select>
  95. </form>
  96. <br />
  97. <div id="txtHint">Customer info will be listed here...</div>
  98.  
  99. </body>
  100. </html>
Add Comment
Please, Sign In to add comment