Prototype / JS Help

T

thesimplerules

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.
 
M

Matt Kruse

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top