Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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

radio javascript checked

document.getElementById('id').checked
Comment

PREVIOUS NEXT
Code Example
Javascript :: vue js routue push 
Javascript :: install react bootstrap 
Javascript :: javascriopt initialize 2d array with size 
Javascript :: prime number in javascript 
Javascript :: how to redirect to a website in react 
Javascript :: next js build command 
Javascript :: react router base url 
Javascript :: Data Down Action Up React 
Javascript :: how to change text color sweet alert IN JS 
Javascript :: create angular component using cli 
Javascript :: how to filter an array by list of objects in javascript 
Javascript :: print whole array javascript 
Javascript :: htpp code 
Javascript :: axios check 401 run function 
Javascript :: how to make your own drop down react native 
Javascript :: call ajax after ajax 
Javascript :: useLocation 
Javascript :: javascript min max array 
Javascript :: Rounding Up To The Nearest Hundred js 
Javascript :: find common characters in two strings javascript 
Javascript :: jquery select the 3rd row of a table 
Javascript :: jquery filter data 
Javascript :: js rock paper scissors 
Javascript :: react extends component construtor super props 
Javascript :: array json 
Javascript :: react JSON data to display in a table 
Javascript :: react select and react hook form 
Javascript :: loop object array 
Javascript :: json full form 
Javascript :: lodash reduce 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =