Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

162
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!