aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes javascript-AJAX regarding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "javascript-AJAX regarding" Watch "javascript-AJAX regarding" New topic
Author

javascript-AJAX regarding

prasad agarwal
Ranch Hand

Joined: Aug 24, 2006
Posts: 44
Hi Javaranch guys,

Well, I have a javascript function which does form validation upon submission and in that function I am calling some
java code which does some querying and if some condition is met I set a flag in a hidden variable.
In the next lines of this function code - I compare/check the hidden variable value and decide if I have to give an
alert message and block form submission or not.

Some of the code is as follows:

AJAX function:


Some of the javascript function code which is run on Form submission:



In the above lines of code always the if(f.block.value == "Y") is false even though it is supposed to be true.
Am I going wrong somewhere or am I missing something?

BUT if I just add this line alert(f.block.value) before if(f.block.value == "Y") it works correct always.
I thought maybe it is because if(f.block.value == "Y") might have run before document.getElementById('block').value = 'Y' in processRequest()
I tried to put some wait/sleep kind of code between but still the if condition is always false but as I said before if I put the alert, it always works correct.
I know I am going wrong somewhere..
I really appreciate your help.. and for your time

Thanks a lot

>
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You are treating asynchronous calls as synchronous.

Eric
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

TIP: Why set a hidden field then check it? Why not just use your ajax response to determine if the form submission can go through? In addition, why not just let the server decide, since you've already submitted the form.


GenRocket - Experts at Building Test Data
prasad agarwal
Ranch Hand

Joined: Aug 24, 2006
Posts: 44
Thank you all, I have decided that I will do the validation in a Java Filter class.
I guess this idea is ok
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61437
    
  67

I would not use a filter for validation.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: javascript-AJAX regarding