It's not a secret anymore!*
The moose likes Servlets and the fly likes Re: Servlet Navigation Problem 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 » Java » Servlets
Bookmark "Re: Servlet Navigation Problem" Watch "Re: Servlet Navigation Problem" New topic
Author

Re: Servlet Navigation Problem

Joe Cheung
Ranch Hand

Joined: Oct 18, 2002
Posts: 104
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


Joe
Phil Chuang
Ranch Hand

Joined: Feb 15, 2003
Posts: 251
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

Joined: Jul 11, 2001
Posts: 15299
    
    6

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.


GenRocket - Experts at Building Test Data
Phil Chuang
Ranch Hand

Joined: Feb 15, 2003
Posts: 251
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 agree. Here's the link: http://aspose.com/file-tools
 
subject: Re: Servlet Navigation Problem
 
Similar Threads
Dynamic Jsp coding
dojo and javascript DOM issue
Anchor tag calling Javascript function
2 newbie questions on errors encountered
Is it possible to embed jsp tags in javascript??