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

89
Views
multiple radio box selected generate one value

I have been trying to generate value to selection all I have been able to get the single value of the single selection.

I want to know how can I combine two selections and generate one value example:

If the person has selected private and half-day I want the value to be a private half-day

if the person has selected private and full-day I want the value to be private full-day

If the person has selected shared and half-day I want the value to be a shared half-day

if the person has selected shared and full-day I want the value to be shared full-day

(function() {
    var stripe = Stripe('pktest');
    var location = document.querySelector('#location');
    
    var btn = document.getElementById('btn');
    
  
    btn.addEventListener('click', async (e) => {
      var occupancy = $('input:radio[name=occupancy]:checked').val();
      var atv = $('input:radio[name=atv]:checked').val();
      e.preventDefault();
      fetch('/checkout_sessions', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
        },
        body: JSON.stringify({
          occupancy: occupancy,
          atv: atv,
          location: location.value,
        }),
      })
      .then((response) => response.json())
      .then((session) => {
        stripe.redirectToCheckout({ sessionId: session.id });
      })
      .catch((error) => {
        console.error('Error:', error);
      });
    });
  })();
<div style="display: flex; width: 100%">
  <input type="radio" name="occupancy" id="private" value="private" checked="checked">
  <label for="private">Private</label>
  <input type="radio" name="occupancy" id="shared" value="shared">
  <label for="shared">Shared</label>
</div>
<div style="display: flex; width:100%">
  <input type="radio" name="atv" id="full-day" value="Full-Day" checked="checked">
  <label for="full-day">Full Day</label>
  <input type="radio" name="atv" id="half-day" value="Half-Day">
  <label for="half-day">Half Day</label>
</div>
<div class="location"><input id="location" type="text" placeholder="location" onfocus="this.placeholder = ''" onblur="this.placeholder = 'location'"> </div>

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

0

  1. Can't you concatenate your occupancy and atv variables into a new unique variable before using fetch()?
  2. As a side note, you should avoid using var so widely in your code. let and const are by far better ways of managing your variables without polluting the global scope.
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!