1

I have a form where the user choose if he/she is SINGLE CITIZENSHIP OR DUAL CITIZENSHIP.
If the user chooses SINGLE CITIZENSHIP the hidden div will not show up and if the user chooses DUAL CITIZENSHIP the hidden div will show below.

<div class="form-row">
  <div class="form-check form-check-inline">
  <input class="form-check-input" type="checkbox" id="inlineCheckbox1" value="option1">
  <label class="form-check-label" for="inlineCheckbox1">Filipino</label>
</div>
<div class="form-check form-check-inline">
  <input class="form-check-input" type="checkbox" id="inlineCheckbox2" value="option2">
  <label class="form-check-label" for="inlineCheckbox2">Dual Citizenship</label>
</div>
</div>

<div id="hidden">
<div class="form-row">
  <div class="form-check form-check-inline">
  <input class="form-check-input" type="checkbox" id="inlineCheckbox1" value="option1">
  <label class="form-check-label" for="inlineCheckbox1">By birth</label>
</div>
<div class="form-check form-check-inline">
  <input class="form-check-input" type="checkbox" id="inlineCheckbox2" value="option2">
  <label class="form-check-label" for="inlineCheckbox2">By Naturalize</label>
</div>
</div>
</div>
Not A Bot
  • 2,474
  • 2
  • 16
  • 33
kiin ken
  • 21
  • 3

2 Answers2

1
let valeInpOne = document.getElementById('inlineCheckbox1'); 
let valeInpTwo = document.getElementById('inlineCheckbox2').value; 
let ele = document.getElementById("hidden");

if(valeInpOne == 'option1'){ ele.hidden = true }else if(valeInpTwo == 'option2'){ ele.hidden = false }
madi.wd
  • 148
  • 1
  • 3
-1

Use change() event of jQuery and show-hide div.

$(document).ready(function () {
    $('#inlineCheckbox2').change(function () {
        if (!this.checked)
           $('#hidden').fadeOut('slow');
        else 
            $('#hidden').fadeIn('slow');
    });
});
#hidden{
  display:none
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="form-row">
  <div class="form-check form-check-inline">
    <input
      class="form-check-input"
      type="checkbox"
      id="inlineCheckbox1"
      value="option1"
    />
    <label class="form-check-label" for="inlineCheckbox1">Filipino</label>
  </div>
  <div class="form-check form-check-inline">
    <input
      class="form-check-input"
      type="checkbox"
      id="inlineCheckbox2"
      value="option2"
    />
    <label class="form-check-label" for="inlineCheckbox2"
      >Dual Citizenship</label
    >
  </div>
</div>

<div id="hidden">
  <div class="form-row">
    <div class="form-check form-check-inline">
      <input
        class="form-check-input"
        type="checkbox"
        id="inlineCheckbox1"
        value="option1"
      />
      <label class="form-check-label" for="inlineCheckbox1">By birth</label>
    </div>
    <div class="form-check form-check-inline">
      <input
        class="form-check-input"
        type="checkbox"
        id="inlineCheckbox2"
        value="option2"
      />
      <label class="form-check-label" for="inlineCheckbox2"
        >By Naturalize</label
      >
    </div>
  </div>
</div>

Refer: https://stackoverflow.com/a/19447642/10971575

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
Pushprajsinh Chudasama
  • 7,772
  • 4
  • 20
  • 43