I am trying to compare 2 values and change the color of one when the condition holds true. But I also have a search-bar and I could not access the tag values when it is wrapped in an <% if %> statement in my javascript function using Rails.
I originally had the code as so <% if track.user.username == current_user.username%> <td class="track_table_current_user"> <span><%= track.user.username %></span></td> <% else %> <td class="td-userName"> <span class="track_table_user_name"> <%= track.user.username %> </span></td> <%end%>
My Ternary as of now:
current_user.username ? "this_current_user" : "other_user" %>">
<%= track.user.username %></td>```
My Sort-Function:
```function trackTableSearch() {
var input, filter, table, tr, td, i, txtValue;
input = document.getElementById("trackTableInput");
filter = input.value.toUpperCase();
table = document.getElementById("tracksTable");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
tdN = tr[i].getElementsByClassName("td-trackName")[0];
tdU = tr[i].getElementsByClassName("track_table_user_name")[0];
tdR = tr[i].getElementsByClassName("td-trackApproved")[0];
tdP = tr[i].getElementsByClassName("td-public")[0];
if ((tdN) || (tdU) || (tdR) || (tdP)) {
txtValueN = tdN.textContent || tdN.innerText;
txtValueU = tdU.textContent || tdU.innerText;
txtValueA = tdR.textContent || tdR.innerText;
txtValueP = tdP.textContent || tdP.innerText;
if (txtValueN.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
}else if (txtValueU.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else if (txtValueA.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
}else if (txtValueP.toUpperCase().indexOf(filter) > -1)
{
tr[i].style.display = "";
}else{
tr[i].style.display = "none";
}
}
}
}```
[Table with names][1]
I want the name to be a different color if it is the actual user logged in.
[1]: https://i.imgur.com/enRT2UR.png
Aucun commentaire:
Enregistrer un commentaire