Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

164
Visualizações
Javascript query selector The string did not match the expected pattern

I'm trying to pass the value of a checkbox only if it is checked, I'm using a text input. I'm running into a syntax issue.. I don't see where I missed any brackets or anything. Any help is appreciated. Fiddle is here also

Thanks

document.querySelector(function() {
    setTarget();
    document.querySelector("#test").change(setTarget);
 

    function setTarget() {
         var tmp ="";
        
        tmp += document.querySelector("#test:checked").value || '';
        document.querySelector('#testtarget').val(tmp);
    }
});
<input type="checkbox" id="test" name="test123" value="testing123"  />this should appear in the text input<br/>
<input type="text" id="testtarget" name="targetTextField" size="31" tabindex="0" maxlength="99" value="">

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

to select checked checkboxes only you can use :checked with your querySelector use it this way

document.querySelectorAll("input[type=checkbox]:checked")

if i am not wrong this is what you exactly want

var cb = document.querySelector("#test"),
    inp = document.querySelector("#testtarget")
    
cb.onchange = function(e){
   inp.value = cb.checked ? cb.value : ""
}
<input type="checkbox" id="test" name="test123" value="testing123"  />this should appear in the text input<br/>
<input type="text" id="testtarget" name="targetTextField" size="31" tabindex="0" maxlength="99" value="">

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda