• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

javascript-AJAX regarding

 
prasad agarwal
Ranch Hand
Posts: 79
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are treating asynchronous calls as synchronous.

Eric
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
prasad agarwal
Ranch Hand
Posts: 79
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64205
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would not use a filter for validation.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic