Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Prototype / JS Help

Reply
Thread Tools

Prototype / JS Help

 
 
thesimplerules@gmail.com
Guest
Posts: n/a
 
      08-23-2006
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.

 
Reply With Quote
 
 
 
 
Matt Kruse
Guest
Posts: n/a
 
      08-23-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> I have this code which uses Prototype functions:


http://www.javascripttoolbox.com/bes...ces/#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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Prototype WTP 0.2 released,this release for Prototype 1.6.0 javascript fish Javascript 0 10-11-2008 07:35 AM
Class prototype vs C function prototype June Lee C++ 2 04-13-2008 08:17 PM
jQuery, Prototype/Script.aculo.us, YUI/Ext, Dojo, MochiKit, Zimbra, etc....help :] hedgehog Javascript 1 04-06-2007 04:01 PM
Prototype Object.extend(new Base() | Hash | Hash.prototype) usage: jacobstr@gmail.com Javascript 3 03-27-2007 07:56 AM
relation between prototype and Prototype.js shypen42@yahoo.fr Javascript 9 05-26-2006 01:13 AM



Advertisments