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

326
Views
jquery - get a value in mix radio button

Would you like to check what wrong in my code, I have 2 group radio button when I click the radio button variable r not have a value :

<script>
$(document).ready(function() {
    var s = 0;
    var l = 0;
    var r = 0;

    $('input[type=radio][name="saverity"]').change(function() {
        s = $(this).val();
        console.log(s);
    });

    $('input[type=radio][name="likehood"]').change(function() {
        l = $(this).val();
        console.log(l);
    });

    r = s * l;
    console.log(r);

});

Thank you very much.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Something like this should work.

$(document).ready(function() {
    var s = 0;
    var l = 0;
    var r = 0;

    $('input[type=radio][name="saverity"]').change(function() {
        s = $(this).val();
      recalculate();
    });

    $('input[type=radio][name="likehood"]').change(function() {
        l = $(this).val();
        recalculate();
    });
    
    function recalculate(){
        r = s * l;
        console.log(r);
    }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<label>
  Saverity
  <input type="radio" name="saverity" value="0">
  <input type="radio" name="saverity" value="1">
</label>
<br>
<label>
  Likehood
  <input type="radio" name="likehood" value="0">
  <input type="radio" name="likehood" value="1">
</label>

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!