Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

168
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda