Thursday, June 23, 2011

Top Rated Ajax Books




All the books listed here have at least a 4 star rating and have been reviewed by at least 10 reviewers. Some reviews are included.


  • Ajax in Action
    by Dave Crane, Eric Pascarello, Darren James
    Best AJAX Book Available Today:
    Ajax in Action by Dave Crane is the best Ajax book on the market today. With over 600 pages of content, this incredibly well-written text explains why Ajax is so powerful and how this simple programming feature (it really isn't difficult to learn at all) has changed web development forever. No longer are users and developers limited to a page reload world, as the power of this technology now has the ability to make the web work like regular applications. It's a trend that has been desired for a loooong time and boy does it ever deliver!!!
    Chapter Overview:
    
    01. Ajax background
    02. Learning to use Ajax
    03. Order with Ajax
    04. Pages as applications
    05. Serve role
    06. User experience
    07. Security and Ajax
    08. Ajax performance
    09. Dynamic double combo example
    10. Type ahead example
    11. Enhanced Ajax web portal
    12. Live search using XSLT
    13. Stand-Alone apps with Ajax
    

  • Professional Ajax (Programmer to Programmer) (Paperback)

    by Nicholas C. Zakas, Jeremy McPeak, Joe Fawcett
    The book does a good job academically of showing how Ajax has evolved (itself a debatable topic) and how it is used in modern-day applications. The book doesn't marry the reader to any one particular web development framework, effectively citing examples in PHP, .NET, and JavaServer Pages. Practically, the authors exhibit a proper mix of (X)HTML, CSS, JavaScript, Dynamic HTML and XmlHttpRequests, showing how the technologies are blended for developing next-gen UIs.

  • AJAX and PHP: Building Responsive Web Applications (Paperback)
    by Cristian Darie, Bogdan Brinzarea, Filip Chereches-Tosa, Mihai Bucica
    AJAX and PHP by Example:This book teaches by example. The first few chapters introduce AJAX and what part PHP, Javascript and XML all play. Then the remainder of the book takes you through several example applications. The example apps are simple enough that you can easily follow. These applications include Form Validation, Chat, Suggest and Autocomplete, Charting with SVG (Scalable Vector Graphics), using grids, and Drag and Drop.

  • Ajax For Dummies (For Dummies (Computer/Tech)) (Paperback)
    by Steve Ph.D. Holzner
    Good coverage with some unique features: Ajax is obviously one of the hot web technologies these days, and now we have the Dummies title that covers it... Ajax for Dummies by Steve Holzner. While it might be easy to write this off as "just another Dummies book", I don't know that I'd be so hasty...
    Contents:
    Part 1 - Getting Started: Ajax 101; It's All About JavaScript
    Part 2 - Programming in Ajax: Getting to Know Ajax; Ajax in Depth
    Part 3 - Ajax Frameworks: Introducing Ajax Frameworks; More Powerful Ajax Frameworks; Server-Side Ajax Frameworks
    Part 4 - In-Depth Ajax Power: Handling XML in Ajax Applications; Working with Cascading Style Sheets in Ajax Applications; Working with Ajax and PHP
    Part 5 - The Part of Tens: Ten Ajax Design Issues You Should Know About; Ten Super-Useful Ajax Resources
    

Monday, May 2, 2011

Highlight HTML Table Rows with JavaScript

Highlight Table Rows on Mouseover


To highlight whole rows, use the following function:

function hiLiteRows(){
 var table = document.getElementById('myTable2');
 for (var i=0;i < table.rows.length;i++)
 {
  table.rows[i].onmouseover = function () {
   this.origColor=this.style.backgroundColor;
   this.style.backgroundColor='#BCD4EC';
  }
  table.rows[i].onmouseout = function () {this.style.backgroundColor=this.origColor;}
 }
}
We use a rows array to get access to table rows. The basic principle is as follows: the original background color is saved in a custom property of a row object to be restored on the mouseout event. The this keyword here refers to the row object.

-->

Highlight TableRows on Click Event


To highlight table rows on the click event, we modify the previous function:

function hiLiteRowsClick(){
 var table = document.getElementById('myTable3');
 for (var i=0;i < table.rows.length;i++){
  table.rows[i].onclick= function () {
   if(!this.hilite){
    this.origColor=this.style.backgroundColor;
    this.style.backgroundColor='#BCD4EC';
    this.hilite = true;
   }
   else{
    this.style.backgroundColor=this.origColor;
    this.hilite = false;
   }
    }
 }
}

Instead of the mouseover event, we use the onclick event to call the anonymous function.
The function will change the background color when a row is clicked for the first time. When a row is clicked again, the original color is restored. To keep track of the click sequence the function uses a custom property called hilite.
This property is set to true on the first click and set to false on the second one.

Related posts:

Hide columns in a table

Expand/collapse rows dynamically


A Simple Way to Highlight Table Cells with JavaScript

Highlight Table Rows on Mouseover


To highlight whole rows, use the following function:

function hiLiteRows(){
 var table = document.getElementById('myTable2');
 for (var i=0;i < table.rows.length;i++)
 {
  table.rows[i].onmouseover = function () {
   this.origColor=this.style.backgroundColor;
   this.style.backgroundColor='#BCD4EC';
  }
  table.rows[i].onmouseout = function () {this.style.backgroundColor=this.origColor;}
 }
}
We use a rows array to get access to table rows. The basic principle is as follows: the original background color is saved in a custom property of a row object to be restored on the mouseout event. The this keyword here refers to the row object.

Highlight TableRows on Click Event


To highlight table rows on the click event, we modify the previous function:

function hiLiteRowsClick(){
 var table = document.getElementById('myTable3');
 for (var i=0;i < table.rows.length;i++){
  table.rows[i].onclick= function () {
   if(!this.hilite){
    this.origColor=this.style.backgroundColor;
    this.style.backgroundColor='#BCD4EC';
    this.hilite = true;
   }
   else{
    this.style.backgroundColor=this.origColor;
    this.hilite = false;
   }
    }
 }
}

Instead of the mouseover event, we use the onclick event to call the anonymous function.
The function will change the background color when a row is clicked for the first time. When a row is clicked again, the original color is restored. To keep track of the click sequence the function uses a custom property called hilite.
This property is set to true on the first click and set to false on the second one.

Friday, December 10, 2010

Insert Backslash Before a Double Quote

Sometimes, you need to dynamically write html text from JavaScript. If the text contains a combination of single and double quotes, you may run into problems. Here is a simple function to avoid those problems.
function insertBackslashBeforeDoubleQuote(str){
 var reg = /"/g;
 var newstr = '\\"';
 return str.replace(reg,newstr);
}
As you see, the function uses a RegExp object on the first line to look for a double quote:
reg = /"/g;
 
The second line defines our replacement string - \"
The backslash in front of the quote has to be escaped with another backslash.
newstr = '\\"';
The last line searches the string and if a double quote is found it is replaced by our newstr pattern.
return str.replace(reg,newstr);
Here is a similar function that inserts a backslash before a single quote if it is contained in the string argument.
function insertBackslashBeforeSingleQuote(str){
 var reg = /'/g;
 var newstr = "\\'"
 return str.replace(reg,newstr);
}


Some other posts:

A JavaScript endsWith function

Highlight HTML Table Rows with JavaScript

Wednesday, November 17, 2010

"Event is Not Defined" Error in Firefox

This error may occur when you try to attach a JavaScript function dynamically to page elements and pass an event to the function. An example:
var inputs = document.getElementsByTagName('input');
for (var i = 0; i < inputs.length; i++) {
    if (inputs[i].type == 'text') {
        inputs[i].onkeypress = function() { return isNumericKey(event); }
    }
};

Here is a listing of the validation function:


/* Numeric Validation */
function isNumericKey(evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode;
    if (charCode >= 48 && charCode <= 57 || charCode == 46) {
        return true;
    }
    else {
        return false;
    }
}
 
This code will work perfectly in IE and it won't allow users to type any other characters than numeric. However, in Firefox, it will throw an error: "event is not defined".

First solution:

Check whether the event is defined in Firefox and attach a reference to the validation function.

if (typeof (event) == "undefined")
    inputs[i].onkeypress = isNegativeNumericKey;
else
    inputs[i].onkeypress = function() { return isNumericKey(event);}

In this case, the event is a global variable that does not exist in Firefox. We could have rewritten the type check as follows:

if (typeof (window.event) == "undefined") ...

Second solution:

Use the following version of the function call in Firefox by passing the event parameter to the function that handles the keypress event:

inputs[i].onkeypress = function(event) { return isNumericKey(event);}

But this would not work in IE.  The solution: normalize the Event interface in the function body:

function(event) { 
   event = event || window.event;
   return isNumericKey(event); 
}

Wednesday, December 9, 2009

A Graph in Table Without Image

Here is a simple script to add a graph to a table cell.





Each table row consists of 2 cells. The first cell contains a numeric value. For each row, in the second cell, the script creates a span with a width equal to the value in the first cell:


It assumes you set a style for a "graph" class. Alternatively, you could set background color in the script. Also, the maximum span width of 100 is assumed.

A side note: to create a rounded span in Firefox, use the following style for the "graph" class:
-moz-border-radius: 10px;
var tbl = document.getElementById('tbl');
for(var i=0; i<tbl.rows.length; i++){
var val = tbl.rows[i].cells[0].innerHTML;
var span = document.createElement("span");
span.style.width = val/100*100;
span.className = "graph";
var cell =tbl.rows[i].cells[1];
cell.style.textAlign= 'left';
cell.appendChild(span);
}

Wednesday, May 20, 2009

Enumerate Array or Object

This is how you could enumerate properties of a JavaScript array:

var arr = ['a', 'b', 'c'];

for (var prop in arr)
alert (prop + ":"+ arr[prop]);

Result:
0:a
1:b
2:c