Step 1:Create index.html file and implement below code.
Category I <input type="radio" name="answer" checked="checked" value="no"/> <br><br> Category II <input type="radio" name="answer" value="yes"/> <br><br> Other Category <input type="radio" name="answer" value="other"/><br> <input style="display:none;" type="text" name="otherAnswer" id="otherAnswer"/>
<script> $(document).ready(function(){ $("input[type='radio']").change(function(){ if($(this).val()=="other") { $("#otherAnswer").show(); } else { $("#otherAnswer").hide(); } }); }); </script>
Complete Code For Displaying Input Field OnClick Of Radio Button In JQuery
<!DOCTYPE html> <html> <head> <title>How To Display Input Field OnClick Of Radio Button In JQuery</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> </head> <style> body { background: black; } </style> <body> <div class="container"> <br><br><br> <div class="text-center"> <h1 id="color" style="color: White;">Display Input Field OnClick Of Radio Button In JQuery</h1> </div> <br> <div class="col-md-2"></div> <div class="col-md-8"> <div class="well"> Category I <input type="radio" name="answer" checked="checked" value="no"/> <br><br> Category II <input type="radio" name="answer" value="yes"/> <br><br> Other Category <input type="radio" name="answer" value="other"/><br> <input style="display:none;" type="text" name="otherAnswer" id="otherAnswer"/> <script> $(document).ready(function(){ $("input[type='radio']").change(function(){ if($(this).val()=="other") { $("#otherAnswer").show(); } else { $("#otherAnswer").hide(); } }); }); </script> </div> </div> <div class="col-md-2"></div> </div> </body> </html>