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

118
Visualizações
Button OnClick only return works on first element

I'm new to web design. I have multiple generated lines of MySQL database elements that I want to make changes to, but when I click on button to show, it only show the first button even if I click the second or third "Add".

enter image description here

<body>
    {% for trail in trails %}
        <div>
            <form>
                {% csrf_token %}
                TrailName:{{trail.1}}
                AreaName:{{trail.2}}
                City:{{trail.3}}
                Length:{{trail.8}}
                RouteType:{{trail.11}}
                AvgRating{{trail.12}}
            </form>
            <button onClick="show()">Add</button>
        </div>
        <div class="part">
            <form action="insert_schedule" method="POST">
                {% csrf_token %}
                <input type="radio" name="trailid" value="{{trail.0}}">
                schedule date:
                <input type="date" name="schedule_date">
                <input type="submit" value="Ok">
            </form>
            <button onClick="hide()">Cancel</button>
        </div>
    {% endfor %}
</body>
function show() {
    var show_part = document.querySelector(".part");
    show_part.style.display = "block";
}

function hide() {
    var show_part = document.querySelector(".part");
    show_part.style.display = "none";
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Given the HTML structure you show:

function show(el){
  const show_part = el.parentElement.nextElementSibling;
  show_part.hidden = false;
}

function hide(el){
  const show_part = el.parentElement;
  show_part.hidden = true;
}

and change your button code to

<button type="button" onclick="show(this)">Cancel</button>
.
.
.
<button type="button" onclick="hide(this)">Cancel</button>
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