Create Your Own Network
Here you can find all of the steps necessary to creating your own net.
Tips & Tricks
Here you can find all of the tricks necessary to spice up your network.
The Buzz
What's all the hubbub? Promote your creations here. Sponsored by Hotline.
Reviews
Here you can find all of the reviews of networks around the community.

Share
Go down
avatar
Boeing University
Boeing University
Posts Posts : 3
Cash Cash : 1967
Karma Karma : 0
Birth Birth : 2012-07-16
View user profile

Switch Case Break in JS (little help?)

on Sat Jul 21, 2018 7:14 pm
I'm sure I'm just overlooking something here but this is driving me crazy and i cant see what I'm doing wrong... i keep getting an error in debugging saying i cant have a break outside of a loop of switch, but this is inside a switch case! here's the code:
Code:
<script type="text/javascript"> var serverdate = '{system.date.today}'; var DD = serverdate.substring(0, 2); var MM = serverdate.substring(3, 5); var YYYY = serverdate.substring(6, 10); var FullCurrentDate = DD + "-" + MM + "-" + YYYY; var FullCurrentDateMM = MM + "-" + YYYY; var StartOfYear = "01-01-" + YYYY var StartOfYearMM = "01-" + YYYY function SwitchMD(MM) { switch (MM) { case "01": var SMD = 31 break; case "02": var SMD = 29 break; case "03": var SMD = 31 break; case "04": var SMD = 30 break; case "05": var SMD = 31 break; case "06": var SMD = 30 break; case "07": var SMD = 31 break; case "08": var SMD = 31 break; case "09": var SMD = 30 break; case "10": var SMD = 31 break; case "11": var SMD = 30 break; case "12": var SMD = 31 break; return SMD   } } var NextMM = MM++; var NextYYYY = YYYY; if (NextMM > 12) { NextMM = "01" var NextYYYY = YYYY++; } var NextMMstart = "01-" + NextMM + "-" + NextYYYY var NextMMslut = SwitchMD(NextMM) + "-" + NextMM + "-" + NextYYYY var LastMM = MM--; var LastYYYY = YYYY; if (MM < 01) { LastMM = "12" var LastYYYY = YYYY--; } var LastMMstart = "01-" + MM + "-" + YYYY var LastMMslut = SwitchMD(LastMM) + "-" + MM + "-" + YYYY var WhoAmI = '{system.page.title}' switch (WhoAmI) { case "Budgetoversigt": var CheckFeltBud = document.getElementsByName("filtercontrol{system.page.id}2")[0].value + "nul"; if (CheckFeltBud == "nul") { document.getElementsByName("filtercontrol{system.page.id}1")[0].value = StartOfYear; document.getElementsByName("filtercontrol{system.page.id}2")[0].value = FullCurrentDate; } break; case "Økonomiske Nøgletal": var CheckFeltOko = document.getElementsByName("filtercontrol{system.page.id}1")[0].value + "nul"; if (CheckFeltOko == "nul") { document.getElementsByName("filtercontrol{system.page.id}1")[0].value = StartOfYearMM; document.getElementsByName("filtercontrol{system.page.id}2")[0].value = FullCurrentDateMM; } break; case "Betalingsoversigt": var CheckFeltBet = document.getElementsByName("filtertocontrol{system.page.id}1")[0].value + "nul"; if (CheckFeltBet == "nul") document.getElementsByName("filterfromcontrol{system.page.id}1")[0].value = NextMMstart; document.getElementsByName("filtertocontrol{system.page.id}1")[0].value = NextMMslut; } break; case "Kassekladde": var CheckFeltKasse = document.getElementsByName("filterfromcontrol{system.page.id}1")[0].value + "nul"; if (CheckFeltKasse == "nul") { document.getElementsByName("filterfromcontrol{system.page.id}1")[0].value = LastMMstart; document.getElementsByName("filtertocontrol{system.page.id}1")[0].value = LastMMslut; } break; case "Kreditorposteringer": var CheckFeltKred = document.getElementsByName("filtertocontrol{system.page.id}1")[0].value + "nul"; if (CheckFeltKred == "nul") { document.getElementsByName("filterfromcontrol{system.page.id}1")[0].value = LastMMstart; document.getElementsByName("filtertocontrol{system.page.id}1")[0].value = LastMMslut; } break; } </script>
avatar
Quentin at Bradford School of Knowledge
Quentin at Bradford School of Knowledge
Posts Posts : 3
Cash Cash : 1115
Karma Karma : 0
Birth Birth : 2011-10-09
View user profilehttp://freedvm.forumotion.com/u7rpgsheet?mode=generate

Re: Switch Case Break in JS (little help?)

on Sat Jul 21, 2018 7:19 pm
Code:
function SwitchMD(MM) {
    switch (MM) {
        case "02":
            var SMD = 29;
            break;
        case "04":
        case "06":
        case "09":
        case "11":
            var SMD = 30;
            break;
        default:
            var SMD = 31;
            break;
    }
return SMD
}

That oughta do it.
From your original paste you didn't have any semi-colons after the var SMD = nn line which might have cause the breakage. Also remember that with a switch statement the interpreter will look for the matching value and continue to interpret code until a break statement is met. Hence you can group together the months with 30 days (September, April, June & Dull November).
Back to top
Permissions in this forum:
You cannot reply to topics in this forum