Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check box if checked then show div else show a different div

Tags:

javascript

php

I have a check box. If i select the check box then i need to display a particular div and if it is left unchecked then display another div . Can someone help me regarding this.

I have researched and i have only found examples where if the checkbox is checked then show the div or else hide the div.But my issue is a little bit different. If this is not possible with a check box and is possible with some other field also please let me know. Thanks in advance.

like image 827
swathi Avatar asked Dec 28 '22 15:12

swathi


1 Answers

document.getElementById('id_of_my_checkbox').onclick = function () {
  document.getElementById('id_of_div_to_show_when_checked').style.display = (this.checked) ? 'block' : 'none';
  document.getElementById('id_of_div_to_hide_when_checked').style.display = (this.checked) ? 'none' : 'block';
};
like image 141
DaveRandom Avatar answered Dec 30 '22 04:12

DaveRandom