• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Re: Servlet Navigation Problem

 
Joe Cheung
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
 
Phil Chuang
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.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic