• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

Function didn't get validated

 
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The following is my code. When the user sign-up with out entering any field its getting stored in data base,same goes with sign-in. Without username and password its just displaying invalid user credentials. It actually should display the alert message. What am i doing wrong. please help me.


How to include onsubmit to return or validate two functions?
 
Saloon Keeper
Posts: 28998
214
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
onsubmit is a form attribute, not a field attribute.
 
Gayathri Gayu
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok I want to validate two function on onsubmit. How will i do that?
 
Gayathri Gayu
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When the user goes for sign-in(Login button) the function validate1() should get validated and for sign-up(Register button) function validate() should get validated. How will i do this? Please help me.
 
Gayathri Gayu
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of validating the function I just added the required in the text fields.
 
Tim Holloway
Saloon Keeper
Posts: 28998
214
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Gayathri Gayu wrote:Instead of validating the function I just added the required in the text fields.




Note that "required" only works for HTML5-compliant web clients. HTML4 did not support this feature. So, for example, IE9 and earlier, this won't work.
 
Gayathri Gayu
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then what should I do to validate both the function?
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I said on th other thread about this html, why are you uing a single form for something that is clearly two forms.
Also you still have multiple fields with the same id (user and pass).  This is wrong.
 
Tim Holloway
Saloon Keeper
Posts: 28998
214
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:
Also you still have multiple fields with the same id (user and pass).  This is wrong.



In fact, this is a violation of proper XML document formation. The XML spec, of which HTML specs are derivative, says that each element must have a unique id value. Failure to observe this restriction can have unpredictable results. Especially if you start browsing the DOM using get element by ID.

And, as Dave has said. Using 1 form to do the work of 2 is not a good idea. Also, forms cannot be nested, so don't even think of doing that!
 
Gayathri Gayu
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have two tabs. One for Sign-In and the second for sign-up. So the sign-in has two fields username and password and sing-up has three with same username, password and email. So when the user sign-up it should validate the function for all three fields

And when the user tries to sign-in with empty username and password field, it should alert the else if condition only. How will i validate this? Please help me.






Added the servlet code and how the form looks for your reference.
 
Sheriff
Posts: 67759
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't seem to be heeding the advice to split your form into two separate forms. Or to be sure that your id values are unique.
 
Gayathri Gayu
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its not that i am not taking the advice, but i don't know how to separate the tab activity. In same structure but in two different forms.
 
Gayathri Gayu
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:You don't seem to be heeding the advice to split your form into two separate forms. Or to be sure that your id values are unique.

What do you mean by the id values are unique?
 
Bear Bibeault
Sheriff
Posts: 67759
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should have one form inside your sign-in-htm div, and another inside the sign-up-htm. Each should have their own validation function, and each should be processed by a different servlet controller.

You can share code with smaller functions, but for now concentrate on getting the structure correct. Optimizations can come later.
 
Bear Bibeault
Sheriff
Posts: 67759
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Gayathri Gayu wrote:What do you mean by the id values are unique?



You have multiple elements withe the same id value ("user" for example). That's not valid HTML.

My advice would be to use class names instead of id values to identify the fields; but if you are going to use id values, they must be unique within the entire HTML page.
 
Gayathri Gayu
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:You should have one form inside your sign-in-htm div, and another inside the sign-up-htm. Each should have their own validation function, and each should be processed by a different servlet controller.

You can share code with smaller functions, but for now concentrate on getting the structure correct. Optimizations can come later.



So i should have separate for like for sign-up . Is this correct?
 
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is happening now?  Are you getting desired output?
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Gayathri Gayu wrote:Is this correct?



Assuming those servlets do what you need, then yes.

But you still need to rename your clashing id fields (user and pass).
 
Gayathri Gayu
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Swastik Dey wrote:What is happening now?  Are you getting desired output?



No i am not getting the desired output. So I just kept one servlet.
 
Gayathri Gayu
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:

Gayathri Gayu wrote:Is this correct?



Assuming those servlets do what you need, then yes.

But you still need to rename your clashing id fields (user and pass).


As I didn't get the desired output, i just merged both to one file. Should i need to rename the user and pass for either sign-up-htm or sign-in-htm?
 
Gayathri Gayu
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Else now i am trying to show a popup form when we click the login button.


The above code how will i display the login page in a popup while clicking login button?
 
Gayathri Gayu
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just changed the user id and password id in singn-in-htm but both the sign-up and sign-in points to same servlet with different fields. Now how will i do?
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The id, not the name...


As Tim said earlier, XML requires you to have unique id values to be valid.

Besides, you are still using a single form for two actions.
Sign-up is not the same thing as Sign-in.
 
Do not meddle in the affairs of dragons - for you are crunchy and good with ketchup. Crunchy tiny ad:
Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders
https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing
reply
    Bookmark Topic Watch Topic
  • New Topic