dcsimg
www.webdeveloper.com
Results 1 to 6 of 6

Thread: Help with executing code in a Switch statement

  1. #1
    Join Date
    Sep 2016
    Posts
    2

    Help with executing code in a Switch statement

    I have some predefined code blocks that can be inserted from a class scheduling provider, and they work fine on their own. I am trying to insert them in a Switch statement based on the day of the week. But I am having problems.

    Here is what the basic code block that works looks like to show a class table:

    Code:
    <script type="text/javascript"
    src="https://app.jackrabbitclass.com/Openings.asp?id=523395&Session=2016-2017&ClassDays=Mon&hidecols=Description,Gender,Days,Ages,StartDate,EndDate,Openings,Session,Tuition&showcols=Room&hidereg=1&sort=Days,StartTime"
    ></script>

    And here is what I have written that I am having problems with getting the class table back from the provider:

    Code:
    <script type="text/javascript">
    var d = new Date()
    var theDay = d.getDay()
    switch (theDay)
    {
    case 1:
    document.write("<b>Monday</b>")
    src="https://app.jackrabbitclass.com/Openings.asp?id=523395&Session=2016-2017&ClassDays=Mon&hidecols=Description,Gender,Days,Ages,StartDate,EndDate,Openings,Session,Tuition&showcols=Room&hidereg=1&sort=Days,StartTime" 
    break
    case 2:
    document.write("<b>Tuesday</b>")
    src="https://app.jackrabbitclass.com/Openings.asp?id=523395&Session=2016-2017&ClassDays=Tue&hidecols=Description,Gender,Days,Ages,StartDate,EndDate,Openings,Session,Tuition&showcols=Room&hidereg=1&sort=Days,StartTime" 
    break
    case 3:
    document.write("<b>Wednesday</b>")
    src="https://app.jackrabbitclass.com/Openings.asp?id=523395&Session=2016-2017&ClassDays=Wed&hidecols=Description,Gender,Days,Ages,StartDate,EndDate,Openings,Session,Tuition&showcols=Room&hidereg=1&sort=Days,StartTime" 
    break
    case 4:
    document.write("<b>Thursday</b>")
    src="https://app.jackrabbitclass.com/Openings.asp?id=523395&Session=2016-2017&ClassDays=Thu&hidecols=Description,Gender,Days,Ages,StartDate,EndDate,Openings,Session,Tuition&showcols=Room&hidereg=1&sort=Days,StartTime"    
    break
    case 5:
    document.write("<b>Friday</b>")
    src="https://app.jackrabbitclass.com/Openings.asp?id=523395&Session=2016-2017&ClassDays=Fri&hidecols=Description,Gender,Days,Ages,StartDate,EndDate,Openings,Session,Tuition&showcols=Room&hidereg=1&sort=Days,StartTime"    
    break
    case 6:
    document.write("<b>Saturday</b>")
    src="https://app.jackrabbitclass.com/Openings.asp?id=523395&Session=2016-2017&ClassDays=Sat&hidecols=Description,Gender,Days,Ages,StartDate,EndDate,Openings,Session,Tuition&showcols=Room&hidereg=1&sort=Days,StartTime" 
    break
    case 0:
    document.write("<b>No Classes Today</b>")
    break
    }
    </script>

  2. #2
    Join Date
    Jan 2004
    Location
    chertsey, a small town s.w. of london, england.
    Posts
    1,712
    Hi there davidbrown14,

    and a warm welcome to these forums.

    Check out the attachment, it may help.

    coothead
    Attached Files Attached Files
    Last edited by coothead; 09-09-2016 at 06:41 AM. Reason: tpynig eorrr
    ~ the original bald headed old fart ~

  3. #3
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    3,704
    Why make a script more complicated than needed
    Code:
    <script>
    d = new Date();
    theDay = d.getDay();
    src = ["https://app.jackrabbitclass.com/Openings.asp?id=523395&Session=2016-2017&ClassDays=",
    "&hidecols=Description,Gender,Days,Ages,StartDate,EndDate,Openings,Session,Tuition&showcols=Room&hidereg=1&sort=Days,StartTime"];
    name = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"][theDay]; 
    header =  "<b>" + ["No Classes Today","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][theDay] +"</b>";
    src = src.join(name);
    console.log(">> "+header);
    console.log(">> "+src);
    </script>
    its not pretty but it works.
    --> JavaScript Frameworks like JQuery, Angular, Node <-- ... and please remember to wrap any code you have in forum tags:-
    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  4. #4
    Join Date
    Sep 2016
    Posts
    2
    Thank you for the suggestion. It did not quite work, but it did show me what I had to do for mine to work. I know it my code is probably too long, but this is just for an internal page.

  5. #5
    Join Date
    Jan 2004
    Location
    chertsey, a small town s.w. of london, england.
    Posts
    1,712
    Hi there davidbrown14,

    to whose code were you referring when you wrote...

    It did not quite work

    coothead
    ~ the original bald headed old fart ~

  6. #6
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    3,704
    Quote Originally Posted by coothead View Post
    Hi there davidbrown14,

    to whose code were you referring when you wrote...
    coothead
    Most often comment given when something doesn't work with no explanation or copy of what it is that didn't work.

    Life would be much simpler if the response was made with a `reply with quote` option selected.
    --> JavaScript Frameworks like JQuery, Angular, Node <-- ... and please remember to wrap any code you have in forum tags:-
    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles