screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/css/bootstrap.min.css" rel="stylesheet"> </head> <body> <div class="container mt-5"> <h3>Bootstrap Radio Button Validation</h3> <form id="myForm"> <div class="form-group"> <label class="control-label">Select a USA college:</label> <div class="radio"> <label><input type="radio" name="college" value="harvard">Harvard University</label> </div> <div class="radio"> <label><input type="radio" name="college" value="stanford">Stanford University</label> </div> <div class="radio"> <label><input type="radio" name="college" value="mit">Massachusetts Institute of Technology</label> </div> </div> <button type="submit" class="btn btn-primary">Submit</button> </form> <p id="selectedCollege"></p> </div> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/js/bootstrap.bundle.min.js"></script> <script> $(document).ready(function () { $('#myForm').submit(function (event) { event.preventDefault(); // Prevent the form from submitting // Check if any radio button is checked var selectedCollege = $('input[name="college"]:checked').val(); if (!selectedCollege) { alert('Please select a college!'); return; } // Display the selected college on the web page $('#selectedCollege').text('Selected College: ' + selectedCollege); }); }); </script> </body> </html>