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

167
Vistas
how do i remember the radio button selection in django

i'm trying to make sure that even if the user refresh the page or goes back and comes back to that page, the radio button is still the same as what the user selects.

N.B: the value of the radio button is saved in sessions

<div class="col-md-1 ps-md-1">
            <input class="align-middle h-100" type="radio" name="deliveryOption"  id="{{option.id}}"
              value="{{option.id}}">
          </div>

my ajax

    $('input[type=radio][name=deliveryOption]').on('change', function(e) {
      e.preventDefault();
      $.ajax({
        type: "POST",
        url: '{% url "checkout:cart_update_delivery" %}',
        data: {
          deliveryoption: $(this).val(),
          csrfmiddlewaretoken: "{{csrf_token}}",
          action: "post",
        },
        success: function (json) {
          document.getElementById("total").innerHTML = json.total;
          document.getElementById("delivery_price").innerHTML = json.delivery_price;
          
        },
        error: function (xhr, errmsg, err) {},
      });
      
    });
  </script>

my view

def cart_update_delivery(request):
cart = Cart(request)
if request.POST.get("action") == "post":
    delivery_option = int(request.POST.get("deliveryoption"))
    delivery_type = DeliveryOptions.objects.get(id=delivery_option)
    updated_total_price = cart.cart_update_delivery(delivery_type.delivery_price)

    session = request.session
    if "purchase" not in request.session:
        session["purchase"] = {
            "delivery_id": delivery_type.id,
        }
    else:
        session["purchase"]["delivery_id"] = delivery_type.id
        session.modified = True

    response = JsonResponse({"total": updated_total_price, "delivery_price": delivery_type.delivery_price})
    return response
about 4 years ago · Juan Pablo Isaza
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