Reply To: Noob Trying to learn Javascript

  • Liz Larsen

    Member
    May 24, 2023 at 8:39 pm
    Points: 5,232
    Rank: UC2 Brainery Purple Belt UC2 Brainery Purple Belt Rank

    It’s your quotation marks.

    When I copy your code into Sublime Text, I can see that they don’t look right:

    field: ”Date”,

    I tried a Find-Replace in Microsoft Word, but it still isn’t right:

    field: “Date”,

    Finally, I just manually typed the ” character into Sublime Text and you can see it formats properly:

    field: "Date",

    See the attached screenshot from Sublime Text. It automatically formats strings as green and the first two aren’t green because the quotation marks are the wrong character and therefore not recognized as strings.

    I know, I know, huge pain in the ass. In the future, I would recommend steering clear of text editors like Word when it comes to writing code. Like I mentioned previously, Sublime Text and Notepad++ are both free and will prevent this issue.

    Here’s the working code:

    var builder = {

    // These map to Text Fields in the Stamp

    textBoxes: [{

    field: "CheckedBy",

    description: "Checked by:",

    default: function () {

    return Collab.user;

    }

    }, {

    field: "Date",

    description: "Date:",

    default: function () {

    var curDate = new Date();

    return (curDate.getMonth() + 1) + "/" + curDate.getDate() + "/" + curDate.getFullYear();

    }

    }, {

    field: "Spec",

    description: "Spec #:",

    default: function () {

    return "";

    }

    }]

    }