• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Re: Servlet Navigation Problem

 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,
I am designing a html as a Login Page. When user enters Username and Password, there are some javascript functions to check whether these 2 fields are empty. If so, a error message will appear and ask user for entering again. If there are data in the fields, then the control will go to the another page. My question is that part of code of the html is shown below:
<form name="Form1" action="Servlet_Path" method="Post">
....
</form>
and I have javascript functions. If everything is ok, the control does not transfer to the servlet specified in the form as I added javascript function in the html. How can I add javascript function to perform client-side checking and ,if no error found, transfer the control to the servlet? I don't want to use window.location because the data entered will appended at the end of the URL. What I want is the data will appear in the URL.
Regards,
Joe
 
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's pretty easy:
I can't provide the exact syntax since I don't remember it and I'd have to look it up But I can provide you with what you need to do.
1) instead of having a submit button, have a regular button that's just labeled submit, and have the onclick point to a javascript function.
2) this javascript function will
-check that the input is valid
--if valid, call document.formname.submit() *or something to this effect*
--if invalid, show a dialog box telling the user of the error.
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also have a regular Submit button and use the onsubmit attribute and call your function. Your function will then need to return true or false indicating whether or not the form should be submitted to the server.
<input type="submit" onsubmit="return checkForm(this)">
Something to that nature.
 
Phil Chuang
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Gregg Bolinger:
You can also have a regular Submit button and use the onsubmit attribute and call your function. Your function will then need to return true or false indicating whether or not the form should be submitted to the server.
<input type="submit" onsubmit="return checkForm(this)">
Something to that nature.


Sure, if you want to do it the easier way
 
I've got no option but to sell you all for scientific experiments. Or a tiny ad:
Enterprise-grade Excel API for Java
https://products.aspose.com/cells/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!