Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

90
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda