This class is a collection of basic and commonly used functions in JavaScript. I coded this class just to validate a form in one of my sites. But it turned out to be more than helpful. I hope it will be of some help for all the web developers.
If you want a new function added or face any difficulty, feel free to contact me.
- Initialize:
- Just include it at the very top of all the JavaScript file as:
<script src="rochak.js" type="text/javascript">
- Just include it at the very top of all the JavaScript file as:
- Usage:
- For example to trim a string:
rochak.Function_Name(Parameter); eg: var str=rochak.trim(str);
- For example to trim a string:
- Complete JavaScript Function List:
- lTrim(string):
- Function to trim all the white spacing from the left side of any string.
- rTrim(string):
- Function to trim all the white spacing from the right side of any string.
- trim(string):
- Function to trim all the white spacing from left and right side of the string.
- isValidEmail(string):
- Function to validate a typical email pattern.
- getType(variable_name):
- Function to find the type of the variable. A Clone of PHP\’s “var_dump()” function.
- inArray(array, string):
- Function to find if the string is in the array. Clone of PHP\’s “in_array()” function.
- inArrayI(array, string):
- Function to find if the string is in the array. Clone of PHP\’s “in_array()” function. (its case insensitive)
- getMouseX(event):
- Function to find the current X position of the mouse/cursor.
- getMouseY(event):
- Function to find the current Y position of the mouse/cursor.
- getMouseXY(event):
- Function to find the current X and Y positions of the mouse/cursor as an array.
- getBrowserName():
- Function to return the name of the web browser.
- isBrowserIe():
- Function to return “true” if the browser is “Microsoft Internet Explorer” else return “false“.
- isBrowserOpera():
- Function to return “true” if the browser is “Opera” else return “false“.
- isBrowserNetscape():
- Function to return “true” if the browser is “Firefox” or “Netscape” else return “false“.
- getTotalImages():
- Function to return the number of images used in the current page.
- explode(delimiter, string):
- Function to Split a string by a specified delimiter. A Clone of PHP\’s “explode” function.
- end(string / array):
- Function to return the last character of a string or the last element of the array. A Clone of PHP\’s “end” function.
- lTrim(string):
Change log (1.1)
- isBrowserFirefox():
- Function to return “true” if the browser is “Firefox” else return “false“.
- isBrowserSafari():
- Function to return “true” if the browser is “Safari” else return “false“.
- isBrowserChrome():
- Function to return “true” if the browser is “Chrome” else return “false“.
- $$(idName):
- Function to similar to “document.getElementById(‘idName’)”.
To download the latest code, right click here and click on “Save link as” or “Save target as”.
Or visit: http://www.phpclasse.org

355 Responses to Rochak.js – Javascript class of common functions