Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js check if radio button is checked

if(document.getElementById('gender_Male').checked) {
  //Male radio button is checked
}else if(document.getElementById('gender_Female').checked) {
  //Female radio button is checked
}
Comment

javascript radio button value if checked

//alert(document.querySelector('input[name = "comp"]:checked').value);

$test=document.querySelector('input[name = "comp"]:checked').value;

if($test="silver") {
        amount=50;
    }else if($test="gold") {
      amount=90;
    }else{
      amount=30;
    }
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 :: javascript falsy 
Javascript :: js convert date to timestamp 
Javascript :: jquery set hidden field value 
Javascript :: javascript string to lowercase 
Javascript :: custom event js 
Javascript :: Close popup window 
Javascript :: how to convert date format using date pipe in angular 
Javascript :: jquery attr 
Javascript :: start date and end date validation antd 
Javascript :: countdown in react js 
Javascript :: creating a 2d array in js 
Javascript :: chrome extension open new tab from popup 
Javascript :: javascript create array with null values 
Javascript :: what is computed in mobx 
Javascript :: worker timeout 
Javascript :: moment get start of week in datetime 
Javascript :: get last word in string js 
Javascript :: js array clone 
Javascript :: javascript regex cheat sheet 
Javascript :: javascript decode a sting in base64 
Javascript :: disable mixed content via javascript 
Javascript :: javascript password hashing 
Javascript :: javascript declare a variable 
Javascript :: Javascript replace div content onclick a button 
Javascript :: scss next js 
Javascript :: jquery each response 
Javascript :: javascript next month from date 
Javascript :: supertest multipart/form-data 
Javascript :: jquery header basic auth 
Javascript :: js pad array 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =