Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. <?php
  2. $con = mysqli_connect("localhost","root","","imetrics") or die ("Cannot connect to the database!");
  3.  
  4. ?>
  5.  
  6. <form name="form1" action="" method="post">
  7. <table>
  8. <tr>
  9. <td>Select Category</td>
  10. <td><select class="form-control" style="width: 150px;" id="categorydd" name="catdd" onChange="change_category()">
  11. <option>Select</option>
  12. <?php
  13. $query=mysqli_query($con, "SELECT category_id, categoryname FROM category WHERE ParentCategoryID IS NULL");
  14. while($row=mysqli_fetch_array($query)) {
  15. ?>
  16. <option value="<?php echo $row["category_id"]; ?>"><?php echo $row["categoryname"]; ?></option>
  17.  
  18. <?php
  19. }
  20. ?>
  21.  
  22.  
  23.  
  24.  
  25. </select>
  26. </td>
  27. </tr>
  28.  
  29. <tr>
  30. <td>Select Subcategory</td>
  31. <td>
  32. <div id="subcategory">
  33. <select class="form-control" style="width: 150px;">
  34. <option>Select</option>
  35. </select>
  36. </div>
  37. </td>
  38. </tr>
  39.  
  40. <tr>
  41. <td>Select Question</td>
  42. <td>
  43. <div id="question">
  44. <select class="form-control" style="width: 150px;">
  45. <option>Select</option>
  46. </select>
  47. </div>
  48. </td>
  49. </tr>
  50.  
  51. </table>
  52.  
  53.  
  54. </form>
  55.  
  56. <script type="text/javascript">
  57.  
  58. function change_category()
  59. {
  60. var xmlhttp = new XMLHttpRequest();
  61. xmlhttp.open("GET","new2.php?category="+document.getElementById("categorydd").value, false);
  62. xmlhttp.send(null);
  63. document.getElementById("subcategory").innerHTML = xmlhttp.responseText;
  64.  
  65. if(document.getElementById("categorydd").value=="Select"){
  66. document.getElementById("question").innerHTML="<select><option>Select</option></select>";
  67. }
  68. }
  69.  
  70.  
  71. function change_question()
  72. {
  73. var xmlhttp = new XMLHttpRequest();
  74. xmlhttp.open("GET","new2.php?subcategory=" + document.getElementById("subcategorydd").value, false);
  75. xmlhttp.send(null);
  76. document.getElementById("question").innerHTML = xmlhttp.responseText;
  77. }
  78.  
  79.  
  80. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement