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

105
Visualizações
How can I get value from loop select in template?

I wan to get value of item price in js for every select what would be my jquery function?

                        {% for package in packages %}
                            <div class="form-group col-md-6">
                                <label for="bedrooms">{{ package.title }}<span style="color: red;">*</span></label>
                                <select class="form-control input-dsn" required id="bedrooms" name="package_{{ package.id }}" onChange="document.getElementByName('package_{{ package.id }}').value = this.value;">

                                    {% for item in package.item_set.all %}
                                        <option  value="{{ item.id }}" data-item-value="{{ item.price }}">{{ item.title }}</option>
                                    {% endfor %}

                                </select>
                            </div>
                        {% endfor %}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

This will (I think) iterate over all the options calling a function on each one.

$(document).ready(function() {
    $("#bedrooms option").each(function() {
        $(this).attr("data-item-value") // is the value you want    
    });
});

Personally I tend to "cheat" and include small JQuery scriptlets in my template where Django can substitute the values I want. The only thing you have to remember is that certain whitespaces become significant. { { is JS. {{ is going to cause the Django template engine to get indigestion!

var option_values = [
    {% for item in package.item_set.all %}{{ item.price }}, {%endfor%} ];
about 4 years ago · Juan Pablo Isaza Relatório
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