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

243
Visualizações
Change button style onclick ASP.NET Web Application

So i have my Index View in which I have a table which lists me all the data i need, thourgh a foreach loop. Here is part of my Index.cshtml

 <table class="table">

        @foreach (var item in Model)
        {
            <tr>
 
                <td style="vertical-align:middle">
                    <div>
                        <img src="@("~/image/"+item.Poza)" asp-append-version="true" width="135" height="210" align="left" style="margin-right: 15px" />
                    </div>
                <td style="vertical-align: middle">
                    <div>
                        <span style="font-weight:bold">Titlu: </span><span>@Html.DisplayFor(modelItem => item.Titlu)</span>
                    </div>
                    <div>
                        <span style="font-weight:bold">An: </span><span> @Html.DisplayFor(modelItem => item.An)</span>
                    </div>
                    <div>
                        <span style="font-weight:bold">Durata: </span><span> @Html.DisplayFor(modelItem => item.Durata)</span>
                    </div>
                    <div>
                        <span style="font-weight:bold">Nota: </span><span> @Html.DisplayFor(modelItem => item.Nota)</span>
                    </div>
                    <div>
                        <span style="font-weight:bold">Recenzie: </span><span> @Html.DisplayFor(modelItem => item.Descriere)</span>
                    </div>

                    </p>
                    @if (item.UserId != ViewBag.userid)
                    {<form asp-action="PostLike" asp-route-id="@item.Id">
                        <input id="btn" type="submit" value="Like" class="btn btn-primary" />
                    </form>}

                </td>
            </tr>
        }
    </table>

Near the end of the page, i have my Like button. I would like to change its color when is pressed, and change it back again at the next click, so the user knows which films he liked and which he didnt. How could i do this? Becuase if I add a simple javascript function like

 function color1() {
      document.getElementById("btn").style.backgroundColor = "red";
    }

it changes only the color of the first button. I mention that everytime the like button is clicked, the page refreshes. So i need that button color to remain unchanged.

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

How are you storing their likes? Need to check that value on page load.

about 4 years ago · Santiago Trujillo 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