Noob Trying to learn Javascript

  • Noob Trying to learn Javascript

    Posted by Kevin Endresen on May 12, 2023 at 10:03 pm

    I am trying to make a stamp. I used one of the examples from bluebeam but when I modify the code to remove what I don’t need, I am no longer prompted for the dialog box. I do still have the Calculation textbox with the defined custom calculation field

    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 “”; } }

    ]

    }

    Isaac Harned replied 9 months, 3 weeks ago 4 Members · 5 Replies
  • 5 Replies
  • Isaac Harned

    Member
    May 15, 2023 at 4:55 pm
    Points: 6,049
    Rank: UC2 Brainery Purple Belt I UC2 Brainery Purple Belt I

    I am playing with this one, but doesn’t look like an easy fix right off the bat. Nothing obvious in coding that I can see, and I’m pretty sure the calculation script is smart enough to account for missing items, but maybe @lizlarsen might have more of an idea.

  • Mac McDoanld

    Member
    May 17, 2023 at 6:35 pm
    Points: 148
    Rank: UC2 Brainery Newbie UC2 Brainery Newbie Belt Rank

    I’m a noob as well, so don’t laugh, but perhaps missing a comma after the last closed bracket. appears in the sample code the open and close bracket for the textBoxes as well as the open and close bracket for the radioButtons, all have a comma following the close bracket.

  • Liz Larsen

    Member
    May 24, 2023 at 12:37 pm
    Points: 4,629
    Rank: UC2 Brainery Orange Belt IIII UC2 Brainery Orange Belt IIII

    I brought it into my favorite JavaScript syntax checker, https://jshint.com, and it showed me that there are indeed some syntax errors.

    Take a look and see if you can figure out where you’re missing brackets and whatnot. I suggest maybe download a free text editor meant specifically for coding, either Sublime Text or Notepad++. Either of these tools will let you see which brackets match, kind of like when you’re editing an Excel formula and it highlights the corresponding parenthesis.

    If you still can’t figure out, let me know and I’ll dig a little deeper. (I’m currently at work where I don’t have access to my coding software.)

    • Liz Larsen

      Member
      May 24, 2023 at 8:39 pm
      Points: 4,629
      Rank: UC2 Brainery Orange Belt IIII UC2 Brainery Orange Belt IIII

      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 "";

      }

      }]

      }

      • Isaac Harned

        Member
        June 9, 2023 at 12:49 am
        Points: 6,049
        Rank: UC2 Brainery Purple Belt I UC2 Brainery Purple Belt I

        LOL finally seeing this. that is both amazing and extremely annoying… Way to go Liz!!

Log in to reply.