does anyone have any other suggestions on this?

bdee1 wrote:
> 
> thanks for getting back to me.
> 
> problem is that i am not sure if i can do all the processing i need  in
> the callback function.  because on my form i have 
> onsubmit="javascript:return validateForm(this)"  so it calls my
> validateForm function and if the validateform function returns true, the
> form submits, otherwise it the form does not submit.
> 
> my validateForm function contains something like this for each check:
> if (!comparePasswords(form.password.value, form.confirmPassword.value))
> {
>      errorsfound += 1;
> }
> 
> 
> so each check calls a function to actually check a field.  if that
> function returns false, then i increment te errrsfound variable.
> 
> then at the end of my validateForm function, if the value of errorsfound
> is greater than 0, i return false from the validateForm function which
> prevents the form from being submitted.
> 
> so although i could use the post callback function in my checkEmailDups
> function to display the necessar errors on the page (in the case of an
> email duplicate being found), ho woudl i prevent the form from being
> sumbitted if that was the only error on the page?
> 
> 
> Rob Desbois-2 wrote:
>> 
>> I've just spotted it after debugging it in Firebug.
>> 
>> Anything which requires having a response for it to execute correctly,
>> must
>> be in the response-handling function.
>> This is behaving exactly as required - the request is asynchronous, and
>> you
>> cannot guarantee that it will execute after the code that comes after it.
>> 
>> The checkEmailDups() function cannot tell you the value without having to
>> wait block execution until the response is received. Far better would be
>> to
>> send the check, and handle both cases within the callback function
>> instead.
>> This will also allow you to remove the (horrible) global variable.
>> 
>> function checkEmailDups(myemail) {
>>    $.post("checkemail.cfm", { email: myemail }, function(data) {
>>       if ($.trim(data) === "available") {
>>          // allow whatever action is being performed
>>       }
>>       else if ($.trim(data) == "taken") {
>>          alert("That email address is taken");
>>       }
>>    });
>> }
>> 
>> --rob
>> 
>> On 7/19/07, bdee1 <[EMAIL PROTECTED]> wrote:
>>>
>>>
>>>
>>> ok i may have figured out why this is happening.
>>> i put replaces alert(dupsfound) with setTimeout('alert(dupsfound)',3000)
>>> so
>>> that the script waited 3 seconds before displaying the alert and then it
>>> displayed the correct value
>>>
>>> so the key is that it IS settign the value properly but it just takes a
>>> minute for the post to complete.
>>>
>>> so.... the next question is, how do i prevent the rest of the function
>>> from
>>> running until the post is finished?
>>>
>>>
>>>
>>> Rob Desbois-2 wrote:
>>> >
>>> > That should work if errorsFound is global - can you provide your code
>>> or
>>> > give us a link to look at?
>>> > --rob
>>> >
>>> > On 7/19/07, bdee1 <[EMAIL PROTECTED]> wrote:
>>> >>
>>> >>
>>> >>
>>> >> i am building a function to validate a registration form for my site.
>>> >> one
>>> >> of
>>> >> the things i need to validate is that the email address entered into
>>> the
>>> >> form does not already exist in the database.
>>> >>
>>> >> in my formValidate function i perform several tests.  if a test fails
>>> i
>>> >> increment a errorsFound variable.  at the end of my function if
>>> >> errorsFound
>>> >> is greater than 0, i do not submit the form.
>>> >>
>>> >> the test for my email field does a $.post to a checkEmail - a page
>>> that
>>> >> checks the database for duplicate email addresses.  then my callback
>>> >> function looks st the results of the post - if duplicates were found,
>>> i
>>> >> increment my errorsFound variable.
>>> >>
>>> >> problem is that from within my $.post callback function i cannot seem
>>> to
>>> >> access my errorsFound variable.
>>> >>
>>> >> how can i get my post callback function to increment my errorsFound
>>> >> variable?
>>> >> --
>>> >> View this message in context:
>>> >>
>>> http://www.nabble.com/changing-the-value-of-a-global-variable-inside-an-post-callback-function--tf4111860s15494.html#a11691585
>>> >> Sent from the JQuery mailing list archive at Nabble.com.
>>> >>
>>> >>
>>> >
>>> >
>>> > --
>>> > Rob Desbois
>>> > Eml: [EMAIL PROTECTED]
>>> > Tel: 01452 760631
>>> > Mob: 07946 705987
>>> > "There's a whale there's a whale there's a whale fish" he cried, and
>>> the
>>> > whale was in full view.
>>> > ...Then ooh welcome. Ahhh. Ooh mug welcome.
>>> >
>>> >
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/changing-the-value-of-a-global-variable-inside-an-post-callback-function--tf4111860s15494.html#a11693506
>>> Sent from the JQuery mailing list archive at Nabble.com.
>>>
>>>
>> 
>> 
>> -- 
>> Rob Desbois
>> Eml: [EMAIL PROTECTED]
>> Tel: 01452 760631
>> Mob: 07946 705987
>> "There's a whale there's a whale there's a whale fish" he cried, and the
>> whale was in full view.
>> ...Then ooh welcome. Ahhh. Ooh mug welcome.
>> 
>> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/changing-the-value-of-a-global-variable-inside-an-post-callback-function--tf4111860s15494.html#a11865355
Sent from the JQuery mailing list archive at Nabble.com.

Reply via email to