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

245
Views
How to get the value of a selected radio input element with javascript
  <input type="radio" name="programming" id="" value="HTML">HTML</input>
  <input type="radio" name="programming" id="" value="C++">C++ </input>
  <input type="radio" name="programming" id="" value="JavaScript">JavaScript </input>
  <input type="radio" name="programming" id="" value="Python">Python</input>
  <button type="submit" class="submit">check</button>

Here is my html code I'm trying to get the value of the selected radio element after the click of the button element.

about 4 years ago · Santiago Gelvez
3 answers
Answer question

0

You can get the value with JavaScript with :

document.querySelector('input[name="programming"]:checked').value
about 4 years ago · Santiago Gelvez Report

0

<input type="radio" name="programming" id="" value="HTML">HTML</input>
<input type="radio" name="programming" id="" value="C++">C++ </input>
<input type="radio" name="programming" id="" value="JavaScript">JavaScript </input>
<input type="radio" name="programming" id="" value="Python">Python</input>
<button type="submit" id="submitBtn" class="submit">check</button>

<script>
    document.getElementById('submitBtn').onclick = function(){
       let val = document.querySelector('input[name="programming"]:checked').value; 
       console.log('Choosen: ', val)
    }
</script>
about 4 years ago · Santiago Gelvez Report

0

Try this code :

const btnSubmit = document.querySelectorAll('input[type="submit"]');

btnSubmit.addEventListener('click', e => {
    let checkedInputValue = document.querySelectorAll('input[name="programming"]:checked').value;
    console.log(checkedInputValue);

});
about 4 years ago · Santiago Gelvez 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!