Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

radio button set value in javascript


//must have a condition to select a value and 
//then get the element of that value individually to set it to checked.
//-you can take the value in var or get it from an object for ex. 
<div class="form-check">
  <label class="form-check-label">
    <input type="radio" class="form-check-input" name="Gender" id="male" value="Male">
      Male
  </label> 
  <label class="form-check-label">
    <input type="radio" class="form-check-input" name="Gender" id="female" value="Female">
      Female
  </label>
</div>

var targetOption='male'
if(targetOption=='female') document.getElementById("female").checked=true;
if(targetOption=='male') document.getElementById("male").checked=true;
 
PREVIOUS NEXT
Tagged: #radio #button #set #javascript
ADD COMMENT
Topic
Name
2+7 =