Solution 1 :

Try below code

<div ng-app="myApp" ng-controller="myCtrl">

    <div>
        <label style="position:relative; left:10px; top:20px">Please Choose One:</label>
        <div style="position: relative; left: 200px; top:-13px">
            <input type="radio" checked="" ng-value="false" id="optionsRadios1" name="optionsRadios"
                ng-model="isDemographics"> OverallCompany
            <div>
                <input type="radio" checked="" ng-value="true" id="optionsRadios1" name="optionsRadios"
                    ng-model="isDemographics">Demographics
            </div>
        </div>
    </div>

    <div class="form-group" ng-show="isDemographics">
        <label style="position: relative; left:10px; top: 28px">Demographics:</label>
        <div style="position: relative; left:200px">
            <select multiple chosen class="chosen-select" id="demo" ng-model="recom.demo"
                ng-options="z as z.demographicName for z in demotype" tabindex="4" style="width:880px;" required>
            </select>
        </div>
    </div>

</div>

<script>
    var app = angular.module('myApp', []);
    app.controller('myCtrl', function ($scope) {
       $scope.isDemographics=true;
    });
</script>

Solution 2 :

You are expecting a parameter in your show function, but in template you are not passing it

<input type="radio" checked="" value="OverallCompany" id="optionsRadios1" name="optionsRadios" ng-model="recom.overall" onclick="show(recom.overall);"> OverallCompany

<input type="radio" checked="" value="Demographics" id="optionsRadios1" name="optionsRadios" ng-model="recom.demo" onclick="show(recom.demo);">Demographics

And you can easily show/hide using ngIf in template itself see this example https://www.w3schools.com/angular/tryit.asp?filename=try_ng_ng-if

Solution 3 :

There is no need of function. Just add ng-show like this:

 <div class="form-group" ng-show="recom.radio == 'Demographics'">
    <label style="position: relative; left:10px; top: 28px">Demographics:</label>
    <div style="position: relative; left:200px">
      <select multiple chosen class="chosen-select" id="demo" ng-model="recom.demo" ng-options="z as z.demographicName for z in demotype" tabindex="4" style="width:880px;" required>
      </select>
    </div>
  </div>

Problem :

I want to open the drop-down option based on the radio button selection. Mu code is in AngularJS

If the Overall Company is selected then the drop-down element should not be shown.
If the demographics is selected then the drop-down element should be shown.

My HTML code is:

<div>
<label style =  "position:relative; left:10px; top:20px">Please Choose One:</label>
<div  style = "position: relative; left: 200px; top:-13px">
<input type="radio" checked="" value="OverallCompany" id="optionsRadios1" name="optionsRadios" ng-model="recom.radio" onclick="show();"> OverallCompany
<div>
<input type="radio" checked="" value="Demographics" id="optionsRadios1" name="optionsRadios" ng-model="recom.radio" onclick="show();">Demographics
</div>
</div>
</div>

<div class="form-group">
<label style="position: relative; left:10px; top: 28px">Demographics:</label>
<div style = "position: relative; left:200px">
<select multiple chosen class="chosen-select" id="demo" ng-model="recom.demo" ng-options = "z as z.demographicName for z in demotype" tabindex="4" style = "width:880px;" required >
</select>
</div>
</div>

I have written a function in java-script for that code is:

 $scope.show = function()
    {
            if($scope.recom.radio=="OverallCompany"){
                document.getElementById('demo').style.display='none';
            }else if($scope.recom.radio=="Demographics"){
                document.getElementById('demo').style.display='block';
            }
        }

Please help how to do it.

Thanks

Comments

Comment posted by stackoverflow.com/help/how-to-answer

Here we love the code and the explanation why it’s working. I invite you to take a moment to read this guide “How do I write a good answer?” here:

Comment posted by Utkarsh Goyal

I have also tried the same thing but still it is not working, giving an error

By