Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $con = mysqli_connect("localhost","root","","imetrics") or die ("Cannot connect to the database!");
- ?>
- <form name="form1" action="" method="post">
- <table>
- <tr>
- <td>Select Category</td>
- <td><select class="form-control" style="width: 150px;" id="categorydd" name="catdd" onChange="change_category()">
- <option>Select</option>
- <?php
- $query=mysqli_query($con, "SELECT category_id, categoryname FROM category WHERE ParentCategoryID IS NULL");
- while($row=mysqli_fetch_array($query)) {
- ?>
- <option value="<?php echo $row["category_id"]; ?>"><?php echo $row["categoryname"]; ?></option>
- <?php
- }
- ?>
- </select>
- </td>
- </tr>
- <tr>
- <td>Select Subcategory</td>
- <td>
- <div id="subcategory">
- <select class="form-control" style="width: 150px;">
- <option>Select</option>
- </select>
- </div>
- </td>
- </tr>
- <tr>
- <td>Select Question</td>
- <td>
- <div id="question">
- <select class="form-control" style="width: 150px;">
- <option>Select</option>
- </select>
- </div>
- </td>
- </tr>
- </table>
- </form>
- <script type="text/javascript">
- function change_category()
- {
- var xmlhttp = new XMLHttpRequest();
- xmlhttp.open("GET","new2.php?category="+document.getElementById("categorydd").value, false);
- xmlhttp.send(null);
- document.getElementById("subcategory").innerHTML = xmlhttp.responseText;
- if(document.getElementById("categorydd").value=="Select"){
- document.getElementById("question").innerHTML="<select><option>Select</option></select>";
- }
- }
- function change_question()
- {
- var xmlhttp = new XMLHttpRequest();
- xmlhttp.open("GET","new2.php?subcategory=" + document.getElementById("subcategorydd").value, false);
- xmlhttp.send(null);
- document.getElementById("question").innerHTML = xmlhttp.responseText;
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement