aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes javaScipt onsubmit problem in jsp 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 "javaScipt onsubmit problem in jsp" Watch "javaScipt onsubmit problem in jsp" New topic
Author

javaScipt onsubmit problem in jsp

naveen yadav
Ranch Hand

Joined: Oct 23, 2011
Posts: 384

hi ranchers,

here is a jsp file which accepts the user id and password.When user does not enters the id and password and submit the form
then it should display the alert box message as wriiten in javascrpit.

but what is happening is it does not showing alert box when i submit the form without providing id and password.




can anyone help with this.


Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61654
    
  67

Use a JavaScript debugger to see what's going in inside your function. Find out:
Is the function being called at all?
Is it fetching the right element values?
Is the comparison working as expected?

and so on

All modern browsers have JavaScript consoles except for Firefox, for which you can use the Firebug plugin.

And, why are you checking for null?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Komal Renu
Ranch Hand

Joined: Jul 21, 2011
Posts: 51
Hi Naveen,

There's a very minor issue in your code. Here it is :

In your javascript function



you have defined both variables as x. whereas the second one where you collect the password should be y.

Moreover instead of using the && operator in the check, you should use ||. Because && operator will not satisfy the condition where one of the fields is null. So all in all your code should be better written as



To enhance it even further you can do separate validation for user id and password. Also note that as good coding practices, its better to give meaningful names to variables.

Hope this helps!

Thanks and Regards,
-------------------------------------------------------------------------------------
Komal Renu | krenu@infocepts.com | www.infocepts.com
-------------------------------------------------------------------------------------
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61654
    
  67

Do you not think it would have been better to help him learn how to find such errors himself?

Sigh.

In any case, I ask again. Why the comparisons for null? The value of an element will never be null.
Komal Renu
Ranch Hand

Joined: Jul 21, 2011
Posts: 51
Yes a check with null isn't actually required. my bad!

Komal
naveen yadav
Ranch Hand

Joined: Oct 23, 2011
Posts: 384

Komal Renu wrote:Hi Naveen,

There's a very minor issue in your code. Here it is :

In your javascript function



you have defined both variables as x. whereas the second one where you collect the password should be y.

Moreover instead of using the && operator in the check, you should use ||. Because && operator will not satisfy the condition where one of the fields is null. So all in all your code should be better written as



To enhance it even further you can do separate validation for user id and password. Also note that as good coding practices, its better to give meaningful names to variables.

Hope this helps!

Thanks and Regards,
-------------------------------------------------------------------------------------
Komal Renu | krenu@infocepts.com | www.infocepts.com
-------------------------------------------------------------------------------------



yes that was the problem and it is resolved.

thanks


Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You should really validate your HTML form, it has tons of errors.

http://validator.w3.org/

Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: javaScipt onsubmit problem in jsp