I'm having a weird issue when trying to use Ajax.Request in a function
within a function.

I'm using LiveValidation from http://www.livevalidation.com/ which
uses prototype.js.  It has a custom attribute that allows you to pass
in a custom function to validate against.  I call this custom function
so that I can check a username against a database using the
Ajax.Request method.

The way it should work is, if the username is not found, it returns
true, otherwise false.  I haven't been able to get that exact result
so I've created some workarounds.  True or False is passed to the
custom function of LiveValidation and validates based on true or

However, for some reason, there is a delay in passing the value from
the LiveValidation custom function.  So let's say the username bee is
taken.  As I type the word 'bee' and the LiveValidation is being
passed to the Ajax.Method, it is returning false.  If I continue to
type, let's say to the word 'beer,' it finally comes back true, even
though 'beer' is not taken. Once I leave that field for the next one,
it validates again and comes back false for the word 'beer.'  Thus the

Here is the code I am using for the Ajax.Request function:

function validateEntry(c,f) {
        var url = "ajaxProcessor.php?f=" + f + "&c=" + c;
        new Ajax.Request(url, {
          method: 'post',
          onComplete: function(transport) {
                if (transport.responseText == "YES"){
                        return entryResponse = 1;
                        return entryResponse = 0;
        if (entryResponse == 0) {
                return false;
                return true;
I'm using entryResponse because I haven't figured out how to return
true or false.

Here is the custom function for LiveValidation:

<script type="text/javascript">

         var f1 = new LiveValidation('f1', { validMessage: "Ok!" } );
          f1.add( Validate.Custom, { against: function(value){ return
validateEntry(value,3) }, failureMessage: "Username already
taken!" } );


Now I tested to see if it was the LiveValidation that was causing the
delay in sending the correct value to the Ajax.Request function and
it's not.  Somewhere within the Ajax.Request method, the return values
are being delayed.

Can anyone help?

You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to