Mohan Arumugam

Mohan Arumugam

  • NA
  • 465
  • 37.4k

Javascript [Radio button]

May 18 2018 2:18 AM

How To Show And Hide Input Fields Based On Radio Button Selection

 
 
here my code 
 
 
 
<script type="text/javascript">
function yesnoCheck() {
if (document.getElementById('yesCheck').checked) {
document.getElementById('ifYes').style.display = 'block';
}
else document.getElementById('ifNo').style.display = 'block';
}
</script>
Yes <input type="radio" onclick="javascript:yesnoCheck();" name="yesno" id="yesCheck">
No <input type="radio" onclick="javascript:yesnoCheck();" name="yesno" id="noCheck"><br>
<div id="ifYes" style="display:none">
If yes, explain: <input type='text' id='yes' name='yes'><br>
What can we do to accommodate you? <input type='text' id='acc' name='acc'>
</div>
<div id="ifNo" style="display:none">
What can we do to accommodate you? <input type='text' id='acc' name='acc'>
</div>
other 3<input type='text' id='other3' name='other3'><br>
other 4<input type='text' id='other4' name='other4'><br>
 
 
Output : [Getting error like this]
 
 
Yes No
If yes, explain:
What can we do to accommodate you?
What can we do to accommodate you?
other 3
other 4
 
 MY REQUIREMENT:
 
if I click yes... things to me 
 
 Yes No
If yes, explain:
What can we do to accommodate you?
other 3
other 4
 
if I click no... things to me 
 
Yes No,
What can we do to accommodate you?
other 3
other 4 
 
 
 
 

Answers (1)