I am new to angularjs and learning to code. I have section with three radio buttons and trying to disable other radio buttons on selecting one. Below is my code
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div class='info-container-content'>
<div>
<label class="info-container-accent" aria-label="Search By Zipcode and Radius">Search By Zipcode and Radius </label>
<input type="radio" name="selectSearch" ng-model="type" />
<input id="search-text-location" type='text' name='zip-location' ng-disabled="" aria-label="Enter Zip Code" placeholder='Enter Zip Code' ng-model="$ctrl.cservice.locsearch.ZipCode" ng-model-options="modelOptions" />
<select name='zip-radius' aria-label="Radius from Zip Code" ng-disabled="" ng-model="$ctrl.cservice.locsearch.SearchRadius" ng-options="item as item.text for item in $ctrl.cservice.locsearch.SearchRadii track by item.value" ng-model-options="modelOptions"></select>
</div>
<br />
<div>
<label class="info-container-accent" aria-label="Search by County">Search by County</label>
<input type="radio" name="selectSearch" ng-model="type" />
<select name='loc-county' aria-label="County" ng-disabled="" ng-model="$ctrl.cservice.locsearch.County" ng-options="item as item.RegionName for item in $ctrl.cservice.locsearch.Counties track by item.RegionCode" ng-model-options="modelOptions">
<option value="">Select a County</option>
</select>
</div>
<br />
<div>
<label class="info-container-accent" class="info-container-accent" aria-label="Search by Properity Region">Search by Properity Region</label>
<input type="radio" name="selectSearch" ng-model="type" />
<select name='loc-region' aria-label="Region" ng-disabled="" ng-model="$ctrl.cservice.locsearch.Region" ng-options="item as item.RegionName for item in $ctrl.cservice.locsearch.Regions track by item.RegionCode" ng-model-options="modelOptions">
<option value="">Select a Region</option>
</select>
</div>
</div>
kindly help.
You should use ng-value
to set the value of each radio button as sample
var app = angular.module("app", []);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app">
<div class='info-container-content'>
<div>
<label class="info-container-accent" aria-label="Search By Zipcode and Radius">Search By Zipcode and Radius </label>
<input type="radio" name="selectSearch" ng-model="type" ng-value="0" />
<input id="search-text-location" type='text' name='zip-location' ng-disabled="type != 0" aria-label="Enter Zip Code" placeholder='Enter Zip Code' ng-model="$ctrl.cservice.locsearch.ZipCode" ng-model-options="modelOptions" />
<select name='zip-radius' aria-label="Radius from Zip Code" ng-disabled="type != 0" ng-model="$ctrl.cservice.locsearch.SearchRadius" ng-options="item as item.text for item in $ctrl.cservice.locsearch.SearchRadii track by item.value" ng-model-options="modelOptions"></select>
</div>
<br />
<div>
<label class="info-container-accent" aria-label="Search by County">Search by County</label>
<input type="radio" name="selectSearch" ng-model="type" ng-value="1"/>
<select name='loc-county' aria-label="County" ng-disabled="type != 1" ng-model="$ctrl.cservice.locsearch.County" ng-options="item as item.RegionName for item in $ctrl.cservice.locsearch.Counties track by item.RegionCode" ng-model-options="modelOptions">
<option value="">Select a County</option>
</select>
</div>
<br />
<div>
<label class="info-container-accent" class="info-container-accent" aria-label="Search by Properity Region">Search by Properity Region</label>
<input type="radio" name="selectSearch" ng-model="type" ng-value="2"/>
<select name='loc-region' aria-label="Region" ng-disabled="type != 2" ng-model="$ctrl.cservice.locsearch.Region" ng-options="item as item.RegionName for item in $ctrl.cservice.locsearch.Regions track by item.RegionCode" ng-model-options="modelOptions">
<option value="">Select a Region</option>
</select>
</div>
</div>
type is : {{type}}
</div>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments