Home
My Quiz

Check Box Gender Select Only Male Or Female

Publish: 12 January 2024, 3:57 am IST | Views: Page View 155

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>User Registration</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 0;
            display: flex;
            align-items: center;
            justify-content: center;
            height: 100vh;
        }

        form {
            background-color: #fff;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            width: 100%; /* Set width to 100% initially */
            max-width: 600px; /* Add max-width */
            margin: 0 auto; /* Center the form */
        }

        label {
            display: block;
            margin-bottom: 8px;
        }

        .educated-options {
            display: flex;
        }

        .educated-options input {
            margin-right: 5px;
        }

        button {
            background-color: #4caf50;
            color: white;
            padding: 10px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }

        button:hover {
            background-color: #45a049;
        }
    </style>
</head>
<body>

<form action="process_registration.php" method="post">
    <!-- Other form fields... -->
    
    <label>Gender:</label>
    <div class="educated-options">
        <input type="checkbox" id="male" name="gender" value="Male" onchange="uncheckOther(this, 'female')">
        <label for="male">Male</label>
        
        <input type="checkbox" id="female" name="gender" value="Female" onchange="uncheckOther(this, 'male')">
        <label for="female">Female</label>
    </div>

    <!-- Other form fields... -->

    <button type="submit">Register</button>
</form>

<script>
    function uncheckOther(checkbox, otherCheckboxId) {
        const otherCheckbox = document.getElementById(otherCheckboxId);
        if (checkbox.checked) {
            otherCheckbox.checked = false;
        }
    }
</script>

</body>
</html>

Categories: Uncategorized