JAVASCRIPT
-
(JS) 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 payed 1000 space credits and in that sum there is…
-
(JS) 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:
-
(JS) 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
-
(JS) 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).
-
(JS) Use include method in IE
Here’s a hack for using the includes method also in the horrible Internet Explorer. [js] if (!String.prototype.includes) { String.prototype.includes = function () { ‘use strict’; return String.prototype.indexOf.apply(this, arguments) !== -1; }; } [/js]
-
(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. [html] <html> <head> <script type="text/javascript"> function DisplayElement(checked) { if (checked) { document.getElementById(‘text’).style.display = ”; } else { document.getElementById(‘text’).style.display = ‘none’; } } </script> </head> <body> <form name="form"> <input type="checkbox" onclick="DisplayElement(this.checked)" checked/> <input…