These are the options in the Select Box. After selecting one of the options, a text box appears.
<select name="category" required id="category" style="width:75%;" onchange = "ShowHideDiv();">
<option value="" disabled selected hidden>Category</option>
<option value="Student">Student</option>
<option value="Teacher">Teacher</option>
<option value="Scientist">Scientist</option>
<option value="Lab Manager">Lab Manager</option>
</select>
These are the text boxes that appears depending on selection of the Select Box:
<div id="roll" style="display: none">
<input name="roll" type="text" id="roll"/>
<span class="highlight"></span>
<span class="bar"></span>
<label>Roll No</label>
</div>
<div id="teacher" style="display: none">
<input name="des" type="text" id="teacher"/>
<span class="highlight"></span>
<span class="bar"></span>
<label>Teacher's Designation</label>
</div>
<div id="scientist" style="display: none">
<input name="des" type="text" id="scientist"/>
<span class="highlight"></span>
<span class="bar"></span>
<label>Scientist's Designation</label>
</div>
<div id="manager" style="display: none">
<input name="des" type="text" id="manager"/>
<span class="highlight"></span>
<span class="bar"></span>
<label>Lab Manager's Designation</label>
</div>
This is the Script for making the text boxes appear upon selection of an option in the select box:
<script type="text/javascript">
function ShowHideDiv()
{
var category = document.getElementById("category");
var roll = document.getElementById("roll");
var teacher = document.getElementById("teacher");
var scientist = document.getElementById("scientist");
var manager = document.getElementById("manager");
roll.style.display = category.value == "Student" ? "block" : "none";
teacher.style.display = category.value == "Teacher"? "block" : "none";
scientist.style.display = category.value == "Scientist" ? "block" : "none";
manager.style.display = category.value == "Lab Manager"? "block" : "none";
}
Below is the code to save the data in the dabase:
<?php
include "connect.php";
if(isset($_POST["submit"]))
{
$name=$_POST["name"];
$gender=$_POST["gender"];
$category=$_POST["category"];
$roll=$_POST["roll"];
$desig=$_POST["des"];
$college=$_POST["college"];
$department=$_POST["department"];
$email=$_POST["email"];
$phno=$_POST["phno"];
$dob=$_POST["dob"];
$lab=$_POST["lab"];
$sql="insert into usercreation values('$name','$gender','$category','$roll','$desig','$college','$department','$email','$phno','$dob','$lab')";
if(mysql_query($sql,$link))
{
header("location:usercreation.php?ok=1");
}
else
{
echo mysql_error();
}
}
?>
I am facing the problem with saving the data of the teacher Text box and scientist Text box. The data for roll and manager is saved into the database and all the rest of the fields.