javascript – show hide text box based on selection of radio button-ThrowExceptions

Exception or error:

I’d like to show/hide text box based on selection of radio buttons.

If I select patient radio button, it will display only patient name text box.

If I select visitor radio button, it will display patient name text box and visitor text box.

How could I show/hide using html/javascript/jquery ? Thanks

How to solve:

I got the solution. I just need to create 2 div. 1 div has 1 text box and another div is 2 text box. And just make show/hide control for these 2 div.Thanks

###

this should get you started. Fool around with the code and let me know what you don’t understand.

function show(){
var pvs = document.getElementsByName('pv');
var pv0 = document.getElementById("patient");
 var pv1 = document.getElementById("visitor");

if (pvs[0].checked){
  
   pv0.style.display='inline-block';
   pv1.style.display='none';


}else{
   pv0.style.display='inline-block';
   pv1.style.display='inline-block';

}


}
#patient,#visitor{
display:none;
}
select patient <input type='radio' name ='pv' onClick="show()"> or visitor
<input type='radio' name ='pv' onClick="show()"><br>

<div id='patient'> patient: <input type='text' ></div><br>
<div id='visitor'>visitor: <input type ='text' ></div><br>

Leave a Reply

Your email address will not be published. Required fields are marked *