Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <script src="js/jquery.js" language="javascript"></script>
- <style>
- ul.submenu{display:none;}
- </style>
- <script type="text/javascript">
- //處理摺疊效果的JQ
- $(function(){
- $(".menu a").click(function(){
- var _this=$(this);
- if(_this.next("ul").length>0){
- _this.html(_this.html()).next().toggle("20000");
- return false;
- }
- });
- $("a").focus( function(){
- $(this).blur();
- });
- });
- </script>
- <script type="text/javascript">
- //處理AJAX的JS
- function showCustomer(str)
- {
- var xmlhttp;
- if (str=="")
- {
- document.getElementById("txtHint").innerHTML="";
- return;
- }
- if (window.XMLHttpRequest)
- {// code for IE7+, Firefox, Chrome, Opera, Safari
- xmlhttp=new XMLHttpRequest();
- }
- else
- {// code for IE6, IE5
- xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
- }
- xmlhttp.onreadystatechange=function()
- {
- if (xmlhttp.readyState==4 && xmlhttp.status==200)
- {
- document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
- }
- }
- //下拉式選單選了以後, 把值塞到另一個dbs.php, 回傳DB中撈出來的資料
- //但是這資料很長, 所以想要可以摺疊,
- //我以為只要回傳的內容可以搭配上面的摺疊JQ就可以達到折疊的效果
- xmlhttp.open("GET","dbs.php?project_id="+str,true);
- xmlhttp.send();
- }
- </script>
- </head>
- <body>
- //以下產生下拉式選單
- <form action="">
- <select name="customers" onchange="showCustomer(this.value)">
- <option value="">Select a customer:</option>
- <?php
- $father_proj_name = array();
- function preparation()
- {
- global $father_proj_name;
- $prepare_SQL = "SELECT * FROM `projects`";
- $prepare_result = mysql_query($prepare_SQL) or die("Query error in preparation father_proj_id");
- while($row = mysql_fetch_array($prepare_result))
- {
- if (is_null($row[parent_id]))
- {
- $father_proj_name[$row[name]] = $row[id];
- }
- }
- }
- //for DB connection
- $dbhost = 'localhost';
- $dbuser = 'redmine_admin';
- $dbpass = 'caswell';
- $dbname = 'redmine_test';
- $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error with MySQL connection');
- mysql_select_db($dbname);
- preparation();
- while (list($key, $val) = each($father_proj_name)) {
- echo "<option value="$val">$key</option>";
- }
- //以上產生下拉式選單
- ?>
- </select>
- </form>
- <br />
- <div id="txtHint">Customer info will be listed here...</div>
- </body>
- </html>
Add Comment
Please, Sign In to add comment