Category: JavaScript

  • Include a JavaScript file in another file

    Including a JavaScript file into another file is a very nice thing to be able to do. It’s something you probably do with almost every other language; it helps keeping files smaller, more readable, and of course, more readable. There are multiple ways to accomplish this and I’ll let you pick the one that works best for you without using the Javascript string replace() function.

    (more…)

  • Validate an email address in JavaScript

    This is my least favorite topic; validating email addresses. There are hundreds of examples using regular expressions that are all slightly different and all have there own quirks with them.

    If validation must be done, I suggest only doing this on the client-side. Ideally the server-side performs email validation by sending an actual email that includes a unique link to validate the email is valid.

    But if JavaScript is a must, here is the best one I’ve found.

    (more…)

  • Why you should use strict with JavaScript

    Many people “dislike” JavaScript for reasons that I cannot understand. I like it and it serves a purpose. JavaScript can be a very forgiving language. By that I mean it let’s you get a way with things that other languages, that are a little stricter, would not. This is where the “use strict” comes into play.

    (more…)

  • Using a forEach loop with JavaScript

    I honestly feel like I’ve been living in the stone age. For years I’ve always used a standard for loop when iterating JavaScript arrays accessing the property with the index of my for loop. No longer, it’s time to upgrade (my brain) and use the forEach loop.

    (more…)

  • Knockout.js foreach afterRender when loop is completed

    I have been using Knockout.js’s afterRender for years to hide a progress bar when the foreach loop completed. All of those years I have been using it incorrectly. Once I read Knockout’s documentation about the foreach data binding function, I realized that it is actually called after each render of the element inside the foreach. This is definitely not how I wanted this function to work. In this Knockout.js tutorial let me show you my solution to accomplish applying the afterRender when the foreach has completed.

    (more…)