Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript check radio button

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

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 :: deep copy object/array 
Javascript :: import { Application } from "express" 
Javascript :: javascript trim spaces 
Javascript :: React Unmounting Lifecycle Method 
Javascript :: javascript how to set cursor for whole page 
Javascript :: responsive grid using antd 
Javascript :: vue add script tags and link tags 
Javascript :: difference between devDependency and dependency 
Javascript :: get the value of css properties js 
Javascript :: dayjs timezone 
Javascript :: repeat react component n times 
Javascript :: how to see chrome sync storage and local storage 
Javascript :: add variables in javascript 
Javascript :: get all the properties of a object in javascript 
Javascript :: how to divide equal 3 parts of an array javascript 
Javascript :: makes number negative javascript 
Javascript :: react event stop propagation 
Javascript :: how to add checkbox in alert box in javascript 
Javascript :: Nuxt JS Adding script tag to particular page 
Javascript :: encode in javascript 
Javascript :: how to run different node app on server different domains 
Javascript :: httpclientmodule is not an angular module 
Javascript :: Javascript find element with focus 
Javascript :: repeat string n times javascript 
Javascript :: create module with routing by angular 
Javascript :: react flip move 
Javascript :: xhr request 
Javascript :: node es6 import 
Javascript :: jquery get nested element 
Javascript :: get size of json object 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =