change radio button checked/unchecked on the basis of input text using jQuery

This solution adds an event listener to your input field (you will need to change the second argument accordingly). Then it simply grabs the input and sets the appropriate checkbox to checked.

Also your IDs can’t be a number.

var currentDate = new Date();
  var currentYear = currentDate.getFullYear();
  let startYear =  currentYear - 10;
  let endYear =  currentYear + 10;

  for ( let i = startYear; i <= endYear; i++ ) {
      <li class="checkbox-container">
        <input value="${i}" type="radio" id=year${i}  name="startYear">
        <label for=year${i}>${i}</label>

    input_year = $(this).val();
    $("#year" + input_year).prop("checked",true);

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top