This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes problem in name and password fields validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "problem in name and password fields validation" Watch "problem in name and password fields validation" New topic
Author

problem in name and password fields validation

Ankit Tripathi
Ranch Hand

Joined: Oct 17, 2009
Posts: 198
hiiiii freinds,
I have designed a login form for processing user login details name and password,but i am facing three problems.
1.even after providing a password in the field "Login Name" a alert window is opening--"please enter the Login Name".
2.even after entering the correct login details a alert box is opening--"please "please enter the Login Name" but alert box--"please enter the password" is never opening even after leaving the password field blank.
3.control is automatically transfered to "loginfailed.html" even after leaving either of fields blank.
code of login.jsp is given below-

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Do you really not indent your code? Why make it difficult for people to read?

Just look at what you're doing: you return a value regardless of the results of the "name" validation. Pretend you're the computer--if you can't trace through the execution of a simple "if" statement you've got a long road ahead of you.
Ankit Tripathi
Ranch Hand

Joined: Oct 17, 2009
Posts: 198
what does that mean


you return a value regardless of the results of the "name" validation.


please explain me clearly should i return "name" and "password"?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

...

Validation fails if either the name or password aren't filled in. You don't ever check the password.
Ankit Tripathi
Ranch Hand

Joined: Oct 17, 2009
Posts: 198
i have modified it but still it is not working

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

*Please* indent your code: do you see how you're making it unnecessarily difficult to see the intent of your code? Compare it with this:Also, please see ItDoesntWorkIsUseless. I see at least one trivial error; can you see it? Refactoring would make the error both (a) easier to spot, and (b) easier to fix, and have the side benefit of giving you something you could use throughout your application. As I refactored it I also found the actual error: simply displaying (via alert or logging) would make this very easy to fix.

That aside: what doesn't work?
Ankit Tripathi
Ranch Hand

Joined: Oct 17, 2009
Posts: 198
thanks a lot.sir.but where the error is?help me in locating it?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I ask again: *what*, specifically, doesn't work?

- Are you validating the form values you think you are? How could you find out?
- If validation fails, are you focusing on the correct form element? Does it look like you are, when you examine the code lines that focus?

You need to slow down and think about what you're doing--I'm *not* going to just tell you what's wrong. The hints above should be enough to help you track down the problem: by answering the questions I've asked you'll find the problems.
 
Don't get me started about those stupid light bulbs.
 
subject: problem in name and password fields validation
 
Similar Threads
Displaying alert message after submit in textbox
Can not Populate the form on combo box change
submit button is not working
Data truncation: Truncated incorrect DOUBLE value:
datas storing twice from servlet to mysql database