Search
 
SCRIPT & CODE EXAMPLE
 

HTML

html radio only one checked

<!--Just manke both names equal -->
<input type="radio" name="options" id="1"/>
<input type="radio" name="options" id="2"/>
Comment

only one selected radio button

<input type="radio" name="test" value="value1"> Value 1
<input type="radio" name="test" value="value2"> Value 2
<input type="radio" name="test" value="value3"> Value 3
Comment

select only one option radio button

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JavaScript Radio Button</title>
</head>

<body>
    <p>Select your size:</p>
    <div id="group">
    </div>

    <p id="output"></p>

    <script>
        const sizes = ['XS', 'S', 'M', 'L', 'XL', 'XXL'];

        // generate the radio groups        
        const group = document.querySelector("#group");
        group.innerHTML = sizes.map((size) => `<div>
                <input type="radio" name="size" value="${size}" id="${size}">
                 <label for="${size}">${size}</label>
            </div>`).join(' ');
        
        // add an event listener for the change event
        const radioButtons = document.querySelectorAll('input[name="size"]');
        for(const radioButton of radioButtons){
            radioButton.addEventListener('change', showSelected);
        }        
        
        function showSelected(e) {
            console.log(e);
            if (this.checked) {
                document.querySelector('#output').innerText = `You selected ${this.value}`;
            }
        }
    </script>
</body>

</html>
Code language: HTML, XML (xml)
Comment

PREVIOUS NEXT
Code Example
Html :: name validation html 
Html :: lorem ipsum hebrew 
Html :: centre text 
Html :: how to get html code in selenium python 
Html :: selected options with link 
Html :: css change color on hover 
Html :: how to show only play button in html audio controls 
Html :: hide top bar menu item odoo 
Html :: bootstrap font-weight bold 
Html :: html get text from file 
Html :: html add vertical space below 
Html :: html tab character tag 
Html :: pass data from blade/laravel to vue 
Html :: get city from location html 
Html :: text bold in .md file 
Html :: embed recaptcha in html 
Html :: two divs in the same place 
Html :: onsubmit in html 
Html :: table row html 
Html :: how to make text center above image html 
Html :: social security number validate regex 
Html :: append button in div 
Html :: tailwind css search bar 
Html :: blue color html code 
Html :: how to write code in html 
Html :: bootstrap input 
Html :: ios viewport cover 
Html :: remove cell border css 
Html :: responsive svg image in html 
Html :: html hyperlink 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =