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

146
Views
jQuery change default radio button value

I am trying to get the radio button that originally had checked against it by default and reset the value of it.

In the example below the value is already set to

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<input type="radio" name="test" value="0" checked>
<input type="radio" name="test" value="1">
<input type="radio" name="test" value="2">

I am using this to select the empty value, but how can I set it to empty first before selecting it?

$('input[name="test"][value=""]').prop('checked', true);
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can make an .each on inputs and check if value is empty example:

$('input[name="test"]').each(function() {
     if($(this).val() === '') {
          //do something
     }
});
about 4 years ago · Juan Pablo Isaza Report

0

Select the checked input using $('input[name="test"][checked]') and update its value with .val("")

const checkedInput = $('input[name="test"][checked]');
checkedInput.val("");
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<input type="radio" name="test" value="0" checked>
<input type="radio" name="test" value="1">
<input type="radio" name="test" value="2">

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!