• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Re: Servlet Navigation Problem

 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
So you made a portal in time and started grabbing people. This tiny ad thinks that's rude:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic