Guest User

Untitled

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