Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2013
    Location
    illinois
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Javascript && formatting Days

    I am new to programming, please be easy with me.

    I am using Informer (a reporting website) which pulls data in from Datatel (a unidata database)

    I am working on a computed column. The computed column ONLY accepts Javascript NO other language.

    What the column should do:

    "If the classes are on Mon & Tue & Wed & Thur & Fri then display Mon-Fri"

    So if the classes fall on all the week days I want to abbreviate the output to only display "Mon-Fri" instead of listing out all the days.

    Here is the code I have: which does not work

    [CODE]
    // sec.monday(etc) is the field in the Datatel database where the values are stored
    var mon = sec.monday;
    var tue = sec.tuesday;
    var wed = sec.wednesday;
    var thur = sec.thursday;
    var fri = sec.friday;
    var sat = sec.saturday;
    var sun = sec.sunday;
    var formatDays = "";

    if (mon =true) && (tue =true) && (wed =true) && (thur =true) && (fri =true);
    then formatDays == mon + "-" + fri;
    [CODE]

    What am I doing wrong?

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,017
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    if (mon =true) && (tue =true) && (wed =true) && (thur =true) && (fri =true); // semi-colon terminates the if clause.

    = is assignment. == is comparison.

    You can shorten it to if(mon && tue && wed && thur && fri) {

    There is no "then" syntax in Javascript. The syntax is (for example) if(x==0) {y=1}


    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
    Last edited by Philip M; 09-17-2013 at 03:09 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    devinjotyler (09-17-2013)

  • #3
    New to the CF scene
    Join Date
    Jul 2013
    Location
    illinois
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    solution

    Figured out a sloution

    [CODE]
    //define variables
    var days = courseSections6_csmdaysk;
    var output = "";
    var formatDays = "Mon-Fri";
    //removes whitespace within data
    var formatBlank = days.replace(/\s+/g, '');

    //if all days are present then display Mon-Fri
    if (days == "M T W TH F")
    {
    output = formatDays;
    }
    else
    {
    output = formatBlank;
    }
    output
    [CODE]


  •  

    Tags for this Thread

    Posting Permissions

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