How to display textbox on radio button selected

1.33K views
0
0 Comments

Show/Hide textbox when radio button is selected

I have 3 radio buttons in a form on selection of one radio button (Other option) I want to display a textbox and hide when I am select Yes or No. Here is the my code.

<input type=”radio” name=”language”> Yes
<input type=”radio” name=”language”> No
<input type=”radio” name=”language”> Other

Please help me out with Javascript or Jquery for this I am a beginner.

htmlAdmin2609 Answered question September 16, 2021
Add a Comment
0
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.js" ></script>
</head>
<body>
No
<input type="radio" name="answer" checked="checked" value="no"/>
Yes
<input type="radio" name="answer" value="yes"/>
Other
<input type="radio" name="answer" value="other"/>
<input style="display:none;" type="text" name="otherAnswer" id="otherAnswer"/>
<script>
$("input[type='radio']").change(function(){
if($(this).val()=="other")
{
$("#otherAnswer").show();
}
else
{
$("#otherAnswer").hide();
$('#otherAnswer').val('');
}

});
</script>
</body>
</html>

Use this code. This code is working fine..

htmlAdmin2609 Changed status to publish September 16, 2021
Add a Comment
Write your answer.
close