Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. statuslist is a list of id´s to a <p> element. rowList is a list of id´s to <tr> in a table.
  2. I´m trying to make a sort function with checkboxes, so that if a person check "Yes" for
  3. instance, I only want to show the rows with status "Yes" and so on. When I run this now
  4. it works for a couple of rows, but not all of them, and "No" and "Do not know" seems to
  5. be corrupting each other.
  6.  
  7. Any tips or thoughts on how to make this work? Ohh, and sorry for the long spaghetti code.
  8. I know this could be written a thousand times better. But I am a noob at JS :)
  9.  
  10.  
  11. var statusList = ["1016", "1018", "1031", "1033", "1035", "1037", "1039"];
  12.  
  13. var rowList = ["row1016", "row1018", "row1031", "row1033", "row1035", "row1037", "row1039"];
  14.  
  15.  
  16. function showYes(){
  17.     for (var i = 0;i < statusList.length;i ++){
  18.         var status = document.getElementById(statusList[i]).innerHTML;
  19.         if (status == "Yes"){
  20.             document.getElementById(rowList[i]).style.display = document.querySelector("#row");
  21.         }
  22.     }
  23. }
  24.  
  25. function dontShowYes(){
  26.     for (var i = 0;i < statusList.length;i ++){
  27.         var status = document.getElementById(statusList[i]).innerHTML;
  28.         if (status == "Yes"){
  29.             document.getElementById(rowList[i]).style.display = "none";
  30.         }
  31.     }
  32. }
  33.  
  34. function showNo(){
  35.     //same function as above but status == "No"
  36. }
  37.  
  38. function dontShowNo(){
  39.     //same function as above but status == "No"
  40. }
  41.  
  42. function showDontKnow(){
  43.     //same function as above but status == "Do not know"
  44. }
  45.  
  46. function dontShowDontKnow(){
  47.     //same function as above but status == "Do not know"
  48. }
  49.  
  50. function showStatus(){
  51.     var yesButton = document.getElementById("checkbox1");
  52.     var noButton = document.getElementById("checkbox2");
  53.     var dontKnowButton = document.getElementById("checkbox3");
  54.  
  55.     if (!yesButton.checked && !noButton.checked && !dontKnowButton.checked){
  56.         showYes();
  57.         showNo();
  58.         showDontKnow();
  59.     } else if (yesButton.checked && !noButton.checked && !dontKnowButton.checked){
  60.         showYes();
  61.         dontShowNo();
  62.         dontShowDontKnow();
  63.     } else if (yesButton.checked && noButton.checked && !dontKnowButton.checked){
  64.         showYes();
  65.         showNo();
  66.         dontShowDontKnow();
  67.     }else if (!yesButton.checked && noButton.checked && !dontKnowButton.checked){
  68.         dontShowYes();
  69.         showNo();
  70.         dontShowDontKnow();
  71.     } else if(!yesButton.checked && noButton.checked && dontKnowButton.checked){
  72.         dontShowYes();
  73.         showNo();
  74.         showDontKnow();
  75.     } else if (!yesButton.checked && !noButton.checked && dontKnowButton.checked){
  76.         dontShowYes();
  77.         dontShowNo();
  78.         showDontKnow();
  79.     } else if (yesButton.checked && noButton.checked && dontKnowButton.checked){
  80.         showYes();
  81.         showNo();
  82.         showDontKnow();
  83.     } else if (yesButton.checked && !noButton.checked && dontKnowButton.checked){
  84.         showYes();
  85.         dontShowNo();
  86.         showDontKnow();
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement