Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- statuslist is a list of id´s to a <p> element. rowList is a list of id´s to <tr> in a table.
- I´m trying to make a sort function with checkboxes, so that if a person check "Yes" for
- instance, I only want to show the rows with status "Yes" and so on. When I run this now
- it works for a couple of rows, but not all of them, and "No" and "Do not know" seems to
- be corrupting each other.
- Any tips or thoughts on how to make this work? Ohh, and sorry for the long spaghetti code.
- I know this could be written a thousand times better. But I am a noob at JS :)
- var statusList = ["1016", "1018", "1031", "1033", "1035", "1037", "1039"];
- var rowList = ["row1016", "row1018", "row1031", "row1033", "row1035", "row1037", "row1039"];
- function showYes(){
- for (var i = 0;i < statusList.length;i ++){
- var status = document.getElementById(statusList[i]).innerHTML;
- if (status == "Yes"){
- document.getElementById(rowList[i]).style.display = document.querySelector("#row");
- }
- }
- }
- function dontShowYes(){
- for (var i = 0;i < statusList.length;i ++){
- var status = document.getElementById(statusList[i]).innerHTML;
- if (status == "Yes"){
- document.getElementById(rowList[i]).style.display = "none";
- }
- }
- }
- function showNo(){
- //same function as above but status == "No"
- }
- function dontShowNo(){
- //same function as above but status == "No"
- }
- function showDontKnow(){
- //same function as above but status == "Do not know"
- }
- function dontShowDontKnow(){
- //same function as above but status == "Do not know"
- }
- function showStatus(){
- var yesButton = document.getElementById("checkbox1");
- var noButton = document.getElementById("checkbox2");
- var dontKnowButton = document.getElementById("checkbox3");
- if (!yesButton.checked && !noButton.checked && !dontKnowButton.checked){
- showYes();
- showNo();
- showDontKnow();
- } else if (yesButton.checked && !noButton.checked && !dontKnowButton.checked){
- showYes();
- dontShowNo();
- dontShowDontKnow();
- } else if (yesButton.checked && noButton.checked && !dontKnowButton.checked){
- showYes();
- showNo();
- dontShowDontKnow();
- }else if (!yesButton.checked && noButton.checked && !dontKnowButton.checked){
- dontShowYes();
- showNo();
- dontShowDontKnow();
- } else if(!yesButton.checked && noButton.checked && dontKnowButton.checked){
- dontShowYes();
- showNo();
- showDontKnow();
- } else if (!yesButton.checked && !noButton.checked && dontKnowButton.checked){
- dontShowYes();
- dontShowNo();
- showDontKnow();
- } else if (yesButton.checked && noButton.checked && dontKnowButton.checked){
- showYes();
- showNo();
- showDontKnow();
- } else if (yesButton.checked && !noButton.checked && dontKnowButton.checked){
- showYes();
- dontShowNo();
- showDontKnow();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement