I am trying to toggle between displaying two div blocks based on the select input using js. Below is the source code :
<html>
<head>
</head>
<style>
.wrapper {
    left: 100px;
    position: relative;
    width: 400px;
    }
   .form-wrapper {
     position: relative;
     width: 200px;
   }
   .label {
  font-size: 1.1em;
  }
  select {
     font-size: .9em;
}
</style>
<body onload="categorySelector();">
<script type="text/javascript">
function init() {
    document.getElementById("add").style.display = "block";
    document.getElementById("search").style.display = "none";   
}
function categorySelector() {
    var val = document.getElementById("operation").value;
    if(val == "addOp") {
        document.getElementById("add").style.display = "block";
        document.getElementById("search").style.display = "none";
    } else if(val == "searchOp") {
        alert(val);
        document.getElementById("add").style.display = "none";
        document.getElementById("search").style.display = "block";
    }
}
</script>
<div class="wrapper">
        <div>
            <label> Select the operation:</label>
            <select id="operation" name="operationSelection" onchange="categorySelector()">
                <option value="addOp"> Addition </option>
                <option value="searchOp"> Search </option>      
            </select>
        </div>                      
        <div id="add" class="form-wrapper">
                <form name="addForm" action="udm_2(working).jsp" method="POST">
                        <div class="label">Select the Category:</div>
                        <div>
                            <input type="radio" name="addCategory" value="wD" checked="checked">
                            <label for="wD">WhiteListed Domain</label>  
                        <div>
                        <div>
                            <input type="radio" name="addCategory" value="wE" checked="checked">
                            <label for="wE">WhiteListed Email</label>   
                        <div>
                        <div>
                            <input type="radio" name="addCategory" value="bD" checked="checked">
                            <label for="bD">BlackListed Domain</label>  
                        <div>
                        <div>
                            <input type="radio" name="addCategory" value="bE" checked="checked">
                            <label for="bE">BlackListed Email</label>   
                        <div>   
                        <input type="submit"/>
                </form>
        </div>
        <div id="search" class="form-wrapper">
                <form name="addForm" action="udm_2(working).jsp" method="POST">
                        <div class="label">Select the Category:</div>
                        <div>
                            <input type="radio" name="addCategory" value="wD" checked="checked">
                            <label for="wD">WhiteListed Domain</label>  
                        <div>
                        <div>
                            <input type="radio" name="addCategory" value="wE" checked="checked">
                            <label for="wE">WhiteListed Email</label>   
                        <div>
                        <div>
                            <input type="radio" name="addCategory" value="bD" checked="checked">
                            <label for="bD">BlackListed Domain</label>  
                        <div>
                        <div>
                            <input type="radio" name="addCategory" value="bE" checked="checked">
                            <label for="bE">BlackListed Email</label>   
                        <div>   
                        <input type="submit"/>
                </form>
        </div>
</div>
</body>
</html>
The problem I face is, on the page load the first div block gets displayed but when I toggle to other select option, the respective div block for the option doesn't get displayed. So can someone please explain why does it not happen?
 
     
     
     
    