Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript check radio button

// Native JS solution:
document.getElementById("_1234").checked = true;
// JQuery solution:
$("#_1234").prop("checked", true);
Comment

javascript is radio button checked

//get radio Buttons (other ways to do this too)
let radioButtons = document.querySelectorAll("input[name=myRadioName]");

//annoyingly the "change" event only fires when a radio button is clicked
//so it does not fire when another one is clicked and it gets unchecked
//so you have to put change listener  on all radio buttons
//and then detect which one is actually selected
for (let i = 0; i < radioButtons.length; i++) {
  	radioButtons[i].addEventListener('change', function() {
  		if (radioButtons[i].checked == 1){
        	alert("checked") ;
    	} else {
    		alert("not checked")
    	}
    });
}

//html look like this:
<form name="myFormName">
  <input type="radio" name="myRadioName"  value="1" />
  <input type="radio" name="myRadioName"  value="2" />
  <input type="radio" name="myRadioName"  value="3" />
</form>
Comment

PREVIOUS NEXT
Code Example
Javascript :: vue ref add class 
Javascript :: set bg image in react 
Javascript :: hover react component 
Javascript :: arry suffle javascript 
Javascript :: jquery merge objects 
Javascript :: JavaScript - How to get the extension of a filename 
Javascript :: check if string is valid date 
Javascript :: filter array of objects to remove duplicate keys 
Javascript :: match word in string js 
Javascript :: credit card mask js 
Javascript :: javascript adding delay 
Javascript :: importing svg into react 
Javascript :: js stop redirect 
Javascript :: how to take a input video 
Javascript :: remove selected bar mui tabs 
Javascript :: p5.js create button 
Javascript :: nock CORS error 
Javascript :: verify if number is not floating 
Javascript :: iframe player youtube onfinish event 
Javascript :: jquery get textarea text 
Javascript :: vue test form input 
Javascript :: js test if string 
Javascript :: get the parent node from child node 
Javascript :: javascript number pyramid 
Javascript :: get union of two lists javascript 
Javascript :: js object for each 
Javascript :: immediately invoked function in javascript 
Javascript :: get all classes of element jquery 
Javascript :: js delete object in dict 
Javascript :: open new tab with angular router 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =