vendredi 27 septembre 2019

check the checkbox if name and value match with the input checkbox field

.html

var url = http: //127.0.0.1:8000/search/?name=san&language=1&cast=1&language=2&cast=3;
  existingUrl(var);

function existingUrl(fullUrl) {
  $('.language').each(function() {
    var hasValue = fullUrl.indexOf($(this).val());
    if (hasValue != -1)
      this.checked = true;

  });
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form method="get">


  <input type="text" name="name" id="name" hidden> language
  <input type="checkbox" name="language" class="language" id="1" value="1"> cast
  <input type="checkbox" name="cast" class="cast" id="2" value="1"> language
  <input type="checkbox" name="language" class="language" id="3" value="2"> cast
  <input type="checkbox" name="cast" class="cast" id="4" value="3"> 
  <input type="submit" value="submit">
</form>

It work fine if all the checkbox input value have different value.If we try with different name having same value it checked all checkbox with that value.




Aucun commentaire:

Enregistrer un commentaire