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

radio javascript checked

document.getElementById('id').checked
Comment

PREVIOUS NEXT
Code Example
Javascript :: reset parsley validation 
Javascript :: js string reverse exception 
Javascript :: shuffle array item javascruitp 
Javascript :: setinterval js 
Javascript :: wordpress not loading jquery 
Javascript :: wordpress disable jquery migrate 
Javascript :: how to run commands in the command prompt using javascript 
Javascript :: javascript remove first character from array list 
Javascript :: javascript define global variable 
Javascript :: convert image object to blob javascript 
Javascript :: @tippyjs/react 
Javascript :: javascript replace array element 
Javascript :: get function parameters count javascript 
Javascript :: switch case in javascript 
Javascript :: jquery .click function call 
Javascript :: remove repeated characters from a string in javascript 
Javascript :: discord client.send_message js 
Javascript :: moment get timezone 
Javascript :: new date parameters javascript 
Javascript :: js array backwards 
Javascript :: js substring first 4 numbwe 
Javascript :: Add an element to an array at a specific index with JavaScript 
Javascript :: max size input file html 
Javascript :: lodash remove null from object 
Javascript :: javascript indexof with condition 
Javascript :: JavaScript read as Json 
Javascript :: react bootstrap add progress bar 
Javascript :: javascript last child 
Javascript :: next router 
Javascript :: how to increment counter button click in javascript 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =