dimanche 18 octobre 2020

Jquery checkbox checked when i add text value input

How i can checked the checkbox when i add text value input check automatically in the list

For example :

  • if you add 222 in the input id=scan will be checked automatically in the list
  • if aleardy checked will be change to unchecked
  • if is not found will be show alert

HTML CODE:

 <input id="Scan" name="Scan" type="text" autocomplete="off" placeholder="Tracking Number" autofocus>
    <br/>
    <input class="custom-control-input" type="checkbox" id="111" value="111">
    <label for="111" class="custom-control-label">111</label>
    <br/>
    <input class="custom-control-input" type="checkbox" id="222" value="222">
    <label for="222" class="custom-control-label">222</label>
    <br/>
    <input class="custom-control-input" type="checkbox" id="333" value="333">
    <label for="333" class="custom-control-label">333</label>
    <br/>
    <input class="custom-control-input" type="checkbox" id="444" value="444">
    <label for="444" class="custom-control-label">444</label>
    <br/>
    <input class="custom-control-input" type="checkbox" id="555" value="555">
    <label for="555" class="custom-control-label">555</label>

JQUERY CODE:

 <script>
    $(document).ready(function() {
      $('#Scan').on('keypress',function(e) {
          if(e.which == 13) {
            Scan=$('#Scan').val();
    
            //if value exsit in the list -> checked
            //if value checked -> dechecked
            //if value not exist -> alert not exist
    
            }
        })
    })
    </script>

Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire