JAVASCRIPT
-
Calculate price excluding VAT
Sometimes you need to calculate the price of a product excluding VAT, and the only details you have is the amount including vat and the vat percent. This might be a bit tricky in some applications when there are mixed VAT percentages. For example, you paid 1000 space credits and in that sum there is…
-
Convert short color hex to pair
If you have a three digit hex for a color. For example #FFF and want to convert it to a 6 digit number here’s a simple way:
-
Validate date in format YYYY-MM-DD
A simple JS function to validate that a date string in the format YYYY-MM-DD is a valid date. Will validate that the day is correct for the given month, including leap years
-
Validate Swedish personnummer and organisationsnummer
JavaScript functions for validating Swedish personal identity numbers (personnummer), and organisation numbers (organisationsnummer). The functions for personal identity number will also validate co-ordination number (samordningsnummer).
-
Use include method in IE
Here’s a hack for using the includes method also in the horrible Internet Explorer.
-
(JS) Newline to br
Replaces newline characters with <br> tags in the same style as the php nl2br function
-
Hide elements with radio buttons
Sometimes you want to show or hide certain elements of a form, depending on the selection of a radiobutton. I am by no means any javascript ninja, but this is one simple way I came up with: This could apply to any element. For example, you could put a whole bunch of elements in…
-
Hide elements with checkbox
This is a slightly edited version of this post. Just to make it work with a checkbox instead of radio buttons.