-4

AngularJs code to display the selecting div content:

<select>
    <option value="0">--Select--</option>
    <option value="1">Individual</option>
    <option value="2">Business</option>
    <option value="3">Others</option>
</select>

If option Individual is selected, it must show the div content with

<div id="individual">
.
.
.
</div>

If option Business is selected it must show the div content with

<div id="business">
.
.
.
</div>

If option Others is selected it must show the div content with

<div id="others">
.
.
.
</div>

Can anyone refer me to any tutorials or link?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Possible duplicate of [How do I change the ID of a HTML element with JavaScript?](https://stackoverflow.com/questions/1650299/how-do-i-change-the-id-of-a-html-element-with-javascript) – takendarkk Jan 10 '18 at 14:47
  • If your question is not the same as the above one, edit your question to explain why. – takendarkk Jan 10 '18 at 14:49
  • Asking for a tutorial or guide is considered off-topic for Stack Overflow. Please read [ask]. – Nikolaj Dam Larsen Jan 10 '18 at 15:52
  • Possible duplicate of [Angular: Show div content depending on which option chosen from drop down menu (ng-show/ng-switch)](https://stackoverflow.com/questions/26389562/angular-show-div-content-depending-on-which-option-chosen-from-drop-down-menu) – ryanyuyu Jan 10 '18 at 21:33
  • Thanks....... i got the solution by using `ng-model and ng-if` – MohanaKrishnan S Jan 12 '18 at 17:30

1 Answers1

0

Use ng-model to store selected value

<select ng-model="selectedVal">
         <option value="0">--Select--</option>
         <option value="1">Individual</option>
         <option value="2">Business</option>
         <option value="3">Others</option>
</select>

Then use ng-switch to display div accordingly

<div ng-switch="selectedVal">
  <div ng-switch-when="1" id="individual">...</div>
  <div ng-switch-when="2" id="business">...</div>
  <div ng-switch-when="3" id="Others">...</div>
  <div ng-switch-default>...</div>
</div>

Check working fiddle here

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Ankur Akvaliya
  • 2,989
  • 4
  • 28
  • 53