This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes HTML, CSS and JavaScript and the fly likes Json/JavaScript problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Json/JavaScript problem" Watch "Json/JavaScript problem" New topic
Author

Json/JavaScript problem

Minh Nguyen Hung
Greenhorn

Joined: Mar 16, 2012
Posts: 5
I have an insert form, which only allow submit if all the input is validated. But in my case, even though the form still displays the errors, but it still allow the submit button to work. Here is my code:

The checkAll() function for submit form validation.


Java Servlet on getJson link.



I try to use firebug to debug what wrong, but i can't get into the getJson and i don't know if it will return true/false or not.
Please someone helps me to fix this issue. Thanks for advance
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61090
    
  66

With all those returns, how can you tell if it's returning try or false? Have you tried using a JavaScript debugger?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61090
    
  66

Please explain the thinking behind this:

Why bother setting result if it's never going to be used?
Minh Nguyen Hung
Greenhorn

Joined: Mar 16, 2012
Posts: 5
Ah it's just my extra code to test for old codes but i forgot to remove it, so don't mind it sir.

About all those return, my idea is if it can't pass at one if check, it will break then display current error.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61090
    
  66

OK, clean up the code first. Messy code can hide a multitude of sins.

Then use a JavaScript debugger to see if the value false is being returned in the cases when you don't want the form to submit.
Minh Nguyen Hung
Greenhorn

Joined: Mar 16, 2012
Posts: 5
Thanks for your reply Bear, it seems i got messed up about how callback works in getJson function. So i decide to change to $.ajax and set aysnc:false. Now the code works fine.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61090
    
  66

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Json/JavaScript problem