Pass Extra Parameters to JavaScript Callback Function

Here is a simple example of a function that takes a callback function as a parameter.   query.send(handleQueryResponse);   function handleQueryResponse(response){   alert(’Processing…’);   } If you wanted to pass extra variables to the callback function, you can do it like this.   var param1 = ‘something’;   var param2 =’something else’;   query.send(function(response) { […]

Javascript Split Function

The Javascript split() function works much the same as the php split() or explode() functions. Basically you take a string at break it up everywhere the delimiter character occurs and return the new strings in an array. So for example, let’s say you have a string like this: [js]var colorString = “red|orange|blue|white|black|brown”;[/js] Which is obviously […]

Javascript Substring

The Javascript substring function is very similar to that of PHP. The first parameter is the start position and the second parameter is the end position. The first character in a javascript string is position 0. Here is a simple example: var birthday = ’1978-07-11′ var year = birthday.substring(0,4) var month = birthday.substring(5,7) var day […]

JavaScript For Loop

Here is an example of the JavaScript for loop (which is identical to the PHP for loop). Again I used Prototype. This basic example illustrates hiding multiple divs. So for example if you dynamically generate a page with divs you can show or hide them with an onchange() function call to something like this. if […]

JavaScript Onclick Return False

Anywhere you put an onclick event with a javascript call, if you add return false then the default behavior (what would have happened without the onclick event) will be disregarded. For example: [html]Click Me[/html] So now when a user clicks the link, the doSomething() function will fire off and the user will not go to […]

JavaScript Form List Key to Index

JavaScript references list menu (dropdown) elements by their index number, not by the list menu’s key. So if you want to preselect a list menu using JavaScript and you know they key in the key/value pairs that comprise the listmenu, here is a simple function I wrote which you pass the field id and the […]

Prototype JavaScript Framework

For anything I do using JavaScript I use the Prototype JavaScript Framework. It features a unique, easy-to-use toolkit for class-driven development and the nicest Ajax library around. It truly bridges cross-browser JavaScript compatibility gaps. You can download it for free from [ viagra pills | viagra online consultation | bruising on cialis | sildenafil […]

PHP JavaScript AJAX

Using Prototype, AJAX is extremely easy. Following is a small function to perform one of the most basic AJAX funstions, to replace the contents of a div element. Modify the function to have the correct php file to hit and loading gif, then simply pass in the div you want to update and the params […]