Prototype / JS Help

Discussion in 'Javascript' started by thesimplerules@gmail.com, Aug 23, 2006.

  1. Guest

    I have this code which uses Prototype functions:

    Event.observe(window, 'load', usinit, false);

    function usinit(){
    $('submit').style.display = 'none';
    Event.observe('UserUsername', 'keyup', warn, false);
    }

    function warn(target){
    var url =
    'users/ajaxinterface/Username/'+escape($F('UserUsername'));
    var pars = '';
    var target = 'us';
    var myAjax = new Ajax.Updater(target, url, {method: 'get',
    parameters: pars});
    }

    The problem is I need to make that code re-usable, right now I have to
    define the target and form key in the functions and thus would need to
    create many functions for a form.

    The problem is that the functions usinit and warn, are called by
    Prototype and so I can't pass parameters to them - atleast I dont think
    I can.
     
    , Aug 23, 2006
    #1
    1. Advertising

  2. Matt Kruse Guest

    wrote:
    > I have this code which uses Prototype functions:


    http://www.javascripttoolbox.com/bestpractices/#prototype

    > Event.observe(window, 'load', usinit, false);
    > function usinit(){
    > $('submit').style.display = 'none';
    > Event.observe('UserUsername', 'keyup', warn, false);
    > }
    > The problem is I need to make that code re-usable, right now I have to
    > define the target and form key in the functions and thus would need to
    > create many functions for a form.


    Try:

    Event.observe(window, 'load', function(){ usinit('submit'); }, false);
    function usinit(id){
    $(id).style.display = 'none';
    Event.observe('UserUsername', 'keyup', warn, false);
    }

    and extend the same concept to the other function.

    --
    Matt Kruse
    http://www.JavascriptToolbox.com
    http://www.AjaxToolbox.com
     
    Matt Kruse, Aug 23, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. June Lee
    Replies:
    2
    Views:
    848
    Jim Cobban
    Apr 13, 2008
  2. Replies:
    9
    Views:
    235
    Thomas 'PointedEars' Lahn
    May 26, 2006
  3. Replies:
    3
    Views:
    290
  4. hedgehog
    Replies:
    1
    Views:
    156
    hedgehog
    Apr 6, 2007
  5. javascript fish
    Replies:
    0
    Views:
    196
    javascript fish
    Oct 11, 2008
Loading...

Share This Page