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…
-
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
-
Log Laravel execution time to console
Put this in app/start/global.php to get Laravels execution time to the browser console log. L4 This works with L5:
-
Open weblinks in external browser when using Phonegap
To prevent a Phonegap-wrapped app from opening external links in the apps webview, use javascript to open the link in the external browser. This works on Android (probably other platforms as well)
-
Convert seconds to days, hours, minutes and seconds
Converting seconds into days, hours, minutes and seconds int days = secondsTotal / 60 / 60 / 24; int hours = (secondsTotal / 60 / 60) % 24; int minutes = (secondsTotal / 60) % 60; int seconds = secondsTotal % 60;
-
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.