Functions
These small functions perform tasks that you may find useful.
Alternative Ways to Define Functions
There is more than one way to define a function in Javascript - in fact there are three. Each works slightly differently and can result in more effective code in the right circumstances.
There is more than one way to define a function in Javascript - in fact there are three. Each works slightly differently and can result in more effective code in the right circumstances.
Optional Function Arguments
Javascript provides a completely different way of making function arguments optional from the way that most programming languages do it. Javascript's way gives you the maximum possible flexibility.
Javascript provides a completely different way of making function arguments optional from the way that most programming languages do it. Javascript's way gives you the maximum possible flexibility.
Adding Javascript from Javascript
When you need to link additional external Javascripts into the head of your page from within your Javascript processing then you need this function that will use the DOM to add the script properly into the head of your page.
When you need to link additional external Javascripts into the head of your page from within your Javascript processing then you need this function that will use the DOM to add the script properly into the head of your page.
Addslashes and StripSlashes
Javascript doesn't provide an equivalent to the addslashes() and stripslashes() functions that are so useful in PHP. We can quickly fix this oversight by defining them ourselves.
Javascript doesn't provide an equivalent to the addslashes() and stripslashes() functions that are so useful in PHP. We can quickly fix this oversight by defining them ourselves.
Targetting External Links to New Window
If you want off site links to open in a new window then you can either add a target attribute manually to each link or use this Javascript function that automatically ads them to all of the external links on the page for you.
If you want off site links to open in a new window then you can either add a target attribute manually to each link or use this Javascript function that automatically ads them to all of the external links on the page for you.
Formatting Numbers
Would you like to be able to display numbers with thousands separators and your choice of decimal point, currency symbol and negative indicator? Well now you can using my formatNumber function.
Would you like to be able to display numbers with thousands separators and your choice of decimal point, currency symbol and negative indicator? Well now you can using my formatNumber function.
Numbers to Words
When you finish a numerical calculation and displaying the answer in numbers just wont do then perhaps converting the number into words is what you need.
When you finish a numerical calculation and displaying the answer in numbers just wont do then perhaps converting the number into words is what you need.
Returning Multiple Values
A function only allows for one value to be returned when it finishes. Here's how to get around that limitation and return multiple values.
A function only allows for one value to be returned when it finishes. Here's how to get around that limitation and return multiple values.
Numeric Test
A quick way to test that numeric input fields actually contain a number.
A quick way to test that numeric input fields actually contain a number.
Hex to Decimal and Decimal to Hex
Convert etween decimal and hexadecimal with these simple functions. Very useful if you randomly generate a number and need the hex equivalent.
Convert etween decimal and hexadecimal with these simple functions. Very useful if you randomly generate a number and need the hex equivalent.
