Monday, February 6, 2012

Traversing DOM using JavaScript

November 22, 2009 by · 1 Comment 

The HTML DOM defines a standard way for accessing and manipulating HTML documents. The DOM presents an HTML document as a tree-structure expressed as an XML document. DOM is a language independent API, as it can be used in Java, .NET, JavaScript and many more. I will use it with JavaScript to for my sample [...]

RGB-to-Hex Conversion

November 3, 2009 by · Leave a Comment 

Question is: How do I convert RGB values of a color to a hexadecimal string? The algorithm is as follows: make sure that RGB values are in the range 0…255, convert RGB values to hex strings, and then merge the three strings. Here is a script that does this conversion: function RGBtoHex(R,G,B) { return toHex(R)+toHex(G)+toHex(B); [...]

charachter validation and count for a textbox – Javascript

November 3, 2009 by · Leave a Comment 

Here I have provided a solution to put a counter for a textbox, that can be updated as each character typed into the textbox. This script will also validate the maximum character length allowed for a textbox. This script will also work when anyone copy/paste the text into the textbox. Textbox can be either single [...]

Enable/Disable DIV tags through Javascript

November 3, 2009 by · Leave a Comment 

Copy/Paste following javascript code snippet. <script type="text/javascript"> function toggleAlert() { toggleDisabled(document.getElementById("content")); } function toggleDisabled(el) { try { el.disabled = el.disabled ? false : true; } catch(E){ } if (el.childNodes && el.childNodes.length > 0) { for (var x = 0; x < el.childNodes.length; x++) { toggleDisabled(el.childNodes[x]); } } } </script> Copy/Paste following HTML code in BODY [...]