Many web developers enjoy using VBScript, due to its many nice, inherent functions. However, Internet Explorer is the only browser which supports VBScript, so for production web applications it is essential that all client-side scripting be written in JavaScript.
No problem, though, we can write VBScript - like functions in JavaScript! Below you'll find a number of VBScript functions implemented in JavaScript. If you decide to use any of these (which I hope you do), please simply include the below lines of text in the JavaScript code, and drop me an email giving me the URL of your site, so I can see your hard work.
// JavaScript Functions Written by: // Scott Mitchell // mitchell@4guysfromrolla.com // https://www.4guysfromrolla.com
FormatNumber(Expression, NumDigitsAfterDecimal, IncludeLeadingDigit, UserParensForNegativeNumbers, GroupDigits) | Returns an expression formatted as a number. |
FormatPercent(Expression, NumDigitsAfterDecimal, IncludeLeadingDigit, UserParensForNegativeNumbers, GroupDigits) | Returns an expression formatted as a percentage (multiplied by 100) with a trailing % character. |
FormatCurrency(Expression, NumDigitsAfterDecimal, IncludeLeadingDigit, UserParensForNegativeNumbers, GroupDigits) | Returns an expression formatted as a currency value. |
FormatDateTime(Date, FormatType) | Returns an expression formatted as a date or time. |
LTrim(string) | Returns a string without leading spaces |
RTrim(string) | Returns a string without trailing spaces |
Trim(string) | Returns a string without leading and trailing spaces |
Len(string) | Returns the length of the specified string. |
Left(string, length) | Returns a specified number of characters from the left side of a string. |
Right(string, length) | Returns a specified number of characters from the right side of a string. |
Mid(string, start, length) | Returns a specified number of characters from a string. |
InStr(strSearch, charSearchFor) |
Returns the position of the character charSearchFor in strSearch
|