Recent Notes

Displaying keyword search results 1 - 6
Created by James on May 01, 2011 20:46:46    Last update: May 01, 2011 20:46:46
Unlike languages such as Python or PHP, an empty array in JavaScript is true . The proper way to test for an empty array is to check the length attribute: // empty array is true var anArray = []; if ...
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 July 04, 2009 16:30:40    Last update: January 11, 2011 21:21:59
If you are looking for a solution for a progress bar, I direct you to the following resources: Bare Naked App provides a simple and elegant solution based on pure CSS with two images. You control the percentage of completion through the background-position attribute of the CSS. HTML: <img src="/images/percentImage.png" alt="... CSS: img.percentImage { background: white url(/imag... Images: (percentImage.png) (percentImage_back.png) WebAppers extended the above solution with JavaScript. They also added several colored images: JQuery UI has a built-in progress bar widget. However, if you want to get to understand some of the foobar needed to get CSS to work (in general) through this example, stay with me for the rest of this note. Initially I was thinking, a progress bar should be easy: just make...
Created by James on October 21, 2010 19:48:36    Last update: October 21, 2010 19:50:43
Use the in operator to enumerate over an object's properties: Use the in operator to list all properties of an object Call the hasOwnProperty function to determine if the property is a direct attribute of the current object, i.e., not some attribute defined somewhere up the prototype chain. Test code (copy and paste to the JavaScript Executor ): function BaseClass() { this.p1 = 'parent.p1... Note that intrinsic attributes such as constructor , prototype are not listed by the in operator.
Created by Fang on April 01, 2010 22:24:58    Last update: April 02, 2010 02:49:38
In this note I'll show you how to create and package a JSP custom tag. The purpose of this tag is to display a random splash image for a home page, among a set of images. We should be able to add or delete candidate splash images from the WAR archive without the need to change the JSP. This is the intended use of the tag: <%@ taglib uri="http://custom.tag.com/demo" prefix... In the above example you provide a set of images named splash*.png (e.g., splash1.png, spalsh2.png, ...), and the tag will pick a random one to display when the JSP is rendered. Let's get started. I'll use Maven for this purpose. Create the standard Maven directory structure ./pom.xml ./src ./src/main ./src/main/jav... pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0"... SplashTag.java package tagdemo; import java.util.ArrayList......
Created by Dr. Xi on November 15, 2007 04:40:44    Last update: November 15, 2007 04:40:44
Here's some simple Ajax code. The Ajax response is delivered as XML with attributes and an array of data payloads contained in CDATA sections: <?xml version="1.0" encoding="utf-8"?> <ajax-re... And the JavaScript that does the Ajax magic: // ajax.js function ajaxGet(url, ajaxCallback) ... And the HTML test code: <html> <head> <script language="JavaScript"...