Recent Notes

Displaying keyword search results 1 - 10
Created by jinx on April 17, 2011 20:40:12    Last update: April 17, 2011 20:40:56
For JavaScript in the <script> block or JavaScript included with a src attribute: nothing more is needed than escaping the single quote or double quote - depending on how the JavaScript string is quoted. Example: var a = 'My name is <?php echo str_replace('\'', '... For inline JavaScript, escape HTML special characters : <?php echo '<a href="test" onclick="alert(\...
Created by James on March 07, 2011 15:49:11    Last update: March 07, 2011 15:49:11
The JavaScript string match method matches the string against a regular expression and returns the matches. // returns ['av'] 'The JavaScript string ma...
Created by James on March 03, 2011 21:48:52    Last update: March 03, 2011 21:48:52
Just another way to left zero-pad a string. function zeroPad(s, length) { if (s.length ...
Created by James on March 03, 2011 20:50:51    Last update: March 03, 2011 20:51:54
This function parses the querystring and returns the query parameters as a map. It calls the string replace function with a function replacement and uses the side effects of the replacement function call to populate the parameter map. function getQueryParameters() { var result ...
Created by James on March 03, 2011 20:29:52    Last update: March 03, 2011 20:30:36
The general syntax for JavaScript string replace is: str.replace(regexp|substr, newSubStr|function[, |n... i.e., The substring to be replaced can be either a string or a regular expression (regex) The replacement string can be a string, or a function which returns the replacement. If the second parameter is a function, the function will be invoked after the match has been performed. The parameters passed to the function are: the matched (to be replaced) substring, the parenthesized submatch strings, offset of the match, and the whole string on which replace is being called. It can take an optional flags argument, but that's not standard . Examples: // replace apples with oranges // only the ...
Created by Dr. Xi on February 08, 2011 14:45:13    Last update: February 08, 2011 14:45:50
The ECMAScript defines these single character escape sequences: Escape Sequence Code Unit Value Name Symbol \b \u0008 backspace <BS> \t \u0009 horizontal tab <HT> \n \u000A line feed (new line) <LF> \v \u000B vertical tab <VT> \f \u000C form feed <FF> \r \u000D carriage return <CR> \" \u0022 double quote " \' \u0027 single quote ' \\ \u005C backslash \ Escape sequences can also be: \0 (backspash zero): the <NUL> character. \xdd (x followed by two hexadecimal digits): a Latin-1 character whose code unit value is the value of the hexadecimal number. \udddd (u followed by 4 hexadecimal digits): A Unicode character whose code unit value equals the value of the hexadecimal number. \ddd (backslash followed by 3 octal digits): a Latin-1 character specified as...
Created by Dr. Xi on October 07, 2010 19:20:55    Last update: January 11, 2011 19:59:17
Like the string trim function, Firefox provides a native implementation for array map, IE doesn't. So we have to create our own map function for Array : if(typeof Array.prototype.map !== 'function') { ... Test page: <html> <head> <title>Array Map</...
Created by James on October 25, 2010 04:45:59    Last update: October 25, 2010 04:45:59
The test method for JavaScript regular expression tests if a string matches the regular expression. Below are some examples: /son/i.test('Jack Jake Jason'); // true /ja/.te...
Created by Dr. Xi on September 11, 2008 23:06:18    Last update: October 06, 2010 03:16:13
Firefox and Google chrome has native support for the trim function for a String. IE (as of IE 8.0) does not provide a trim function for String. Using the JavaScript Executor , if you execute: 'abcd '.trim you get: function trim() { [native code] } in Firefox and Google Chrome. But you get nothing in IE. If you try to execute the trim method on a String: 'abcd '.trim() you get this in IE: TypeError: Object doesn't support this property or... In order to have the trim function across all browsers, define this function: if(typeof String.prototype.trim !== 'function') { ... Or, if you use jQuery, you can use $.trim()
Created by James on September 03, 2010 15:34:30    Last update: September 03, 2010 15:34:43
Combine the elements of a JavaScript array to a string by the join method: a = [ 'Eeny', 'meeny', 'miny', 'moe' ]; a.join(...
Previous  1 2 Next