• 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
  • Paul Clapham
  • Bear Bibeault
  • Liutauras Vilda
  • Devaka Cooray
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

java script

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1.We can do validations in a form using java script.ie.If we keep one text field blank we give an alert message.After clicking "ok"
of alert message control goes to the next jsp.I want to keep control in the same page(provided any blank field is there).Can you write how this problem to be solved?
 
Ranch Hand
Posts: 3143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this question is more appropriate to the HTML & Javascript forum so I am moving it there.
 
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, when you click a button, it will not go to the next page unless you tell it to, so be default, it will stay on the current page. That is unless you use a submit button.
I have done form validation in two different forms. One is where I use a submit button and have a function that gets called onSubmit in the form tag. This works well, you just have to return false if the form has error and you don't want it to submit. If you have it return true, it will submit. So basically, you run down all of the validation you need, if there is an error, return false and at the very end of the function return true. Because if it hits one of the return false, it takes you out of the function so the return true never gets executed. If it gets to return true, then all the validation must have passed, so you want it to submit.
The second form is similar, except you have a button that has an onClick event that checks the form. If there is an error you direct them to the error with an alert box (same as above) and then do something like field.focus() to put them on the field with the error. If there are no errors, then at the end of the function have a form.submit() call that submits the form for you.
But to answer your question, the page won't submit unless you tell it to, so it will stay right where you want.
Bill
 
We must storm this mad man's lab and destroy his villanous bomb! Are you with me tiny ad?
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!