File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "javascript-AJAX regarding" Watch "javascript-AJAX regarding" New topic

javascript-AJAX regarding

prasad agarwal
Ranch Hand

Joined: Aug 24, 2006
Posts: 67
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

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

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

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: 67
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

Joined: Jan 10, 2002
Posts: 63870

I would not use a filter for validation.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: javascript-AJAX regarding
It's not a secret anymore!