In this tutorial, learn how to show/hide different HTML form on radio button selection. When the user selects the radio button, upon each selection, a new form will be open. Each time, the user will see a different form which you can use for multiple login systems.
You can also use this for multiple registration systems. To allow different users to register for their relevant section. Each form contains the submit button to get user input on submission. You may also like to read Show/Hide Div On Radio Button Selected Using JQuery.
Show Different HTML Form On Radio Button Selection
There are three radio buttons and three forms available in the below example. When you choose the option, its matching login form will open. If you have multiple types of users, employees and managers login.
You can use this form for your project. It’s the easiest method which uses jQuery to show form dynamically.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | <style> .myDiv{ display:none; } #showOne{ color:red; border:1px solid red; padding:10px; } #showTwo{ color:green; border:1px solid green; padding:10px; } #showThree{ color:blue; border:1px solid blue; padding:10px; } </style> <script> $(document).ready(function(){ $('input[type="radio"]').click(function(){ var demovalue = $(this).val(); $("div.myDiv").hide(); $("#show"+demovalue).show(); }); }); </script> <input type="radio" name="demo" value="One"/> Subscriber Login <input type="radio" name="demo" value="Two"/> Employee Login <input type="radio" name="demo" value="Three"/> Manager Login <div id="showOne" class="myDiv"> <strong>Subscriber Login Form</strong> <form id="MyForm" action="" method="post"> <label>Enter Name</label> <input type="text" name="name" placeholder="Enter your name"/></br> <label>Enter Email</label> <input type="email" name="email" placeholder="Enter your email"/></br> <input type="button" class="btn btn-default" name="submit" value="Submit"/> </form> </div> <div id="showTwo" class="myDiv"> <strong>Employee Login Form</strong> <form id="MyForm" action="" method="post"> <label>Enter Name</label> <input type="text" name="name" placeholder="Enter your name"/></br> <label>Enter Email</label> <input type="email" name="email" placeholder="Enter your email"/></br> <input type="button" class="btn btn-default" name="submit" value="Submit"/> </form> </div> <div id="showThree" class="myDiv"> <strong>Manager Login Form</strong> <form id="MyForm" action="" method="post"> <label>Enter Name</label> <input type="text" name="name" placeholder="Enter your name"/></br> <label>Enter Email</label> <input type="email" name="email" placeholder="Enter your email"/></br> <input type="button" class="btn btn-default" name="submit" value="Submit"/> </form> </div> |
Output
Subscriber Login
Employee Login
Manager Login
Click any of the above-given radio buttons to get the relevant form. When you choose a button, you will get a new form to use for your users.
Each form is of a different style with the submit button. You can change the above-given forms as per your requirement.
You may also like to read
- Get Selected Radio Button Value Using JQuery
- Show/Hide Div On Dropdown Selected Using JQuery
- Change Image On Dropdown Select Option Using JQuery
Hope, you like this post of how to show different HTML form on radio button selection. If you have any query regarding the tutorial, please comment below.
References
- Stackoverflow Discussion on Displaying forms, based on selection of Radio Button
- Ubuntu Forum Show more forms on Radio Button selection
Also tell, which method you are using to create your own radio button option for forms.