Searched the internet. Learnt how to do this. Implemented it. But it doesn't work. I want to show the div student when student is selected and the div teacher when teacher is selected. This is a part of a jsp file.
HTML code :
<table>
<tr>
<td>
<select id="userType">
<option value="student">STUDENT</option>
<option value="teacher">TEACHER</option>
<option value="admin">ADMIN</option>
</select>
</td>
</tr>
<table>
Javascript code:
<script type="text/javascript">
var elem = document.getElementById('userType');
elem.onchange = function() {
var studentDiv = document.getElementById('student');
var teacherDiv = document.getElementById('teacher');
studentDiv.style.display = (this.value.equals("student")) ? 'block':'none';
teacherDiv.style.display = (this.value.equals("teacher")) ? 'block':'none';
};
</script>
I've been trying to get this right since morning. Tried other methods as well. Nothing works. What am I doing wrong?