inicio mail me! sindicaci;ón

Prototype library examples

The Prototype library, including script.aculo.us and a few others are a critical part of my development toolbox. These Javascript frameworks provide the foundation for creating interactive, usuable, fast and light-weight web-applications. Below are just a few examples of functions I use all the time.

  1. Ajax.Request
    Take a look at the two functions below. Using the Ajax.Request method you can call a processing file, all that processing file needs to do is output some text who response is passed to the onComplete function, displayProcessIt() and from there, you can generate a complete page of data, hide/show lists elements, divs, whatever you need.

    function processIt(){
      var url = '/path/processing_file.aspx';
      var pars = 'param1='+param1Val;
      var myAjax = new Ajax.Request( url, { method: 'get', parameters: pars, onComplete: displayProcessIt });
    }
    function displayProcessIt(strData){
      var strResponse = strData.responseText
      // Do whatever you want with this data on the client
    }
    

    All I know is after I learned how to use this one piece of functionality, my development become that much easier. That’s not to say this technique is ground-breaking or new, I know I’ve written enough “kind-of-does-this” code over the years.

  2. Element.show(), Element.hide(), Element.toggle()

    Yes, I know these are very self-explanatory, but these are three sweet gems. All you do is create a pointer to an element by it’s ID and there you go, hide, show, toggle, beautiful…

    function doSomething(e1){
      Element.toggle($(e1));
    }
    

    Using $ creates a reference to that object by id and toggle…well, it toggles the display of the referenced element.

Comments are closed.