File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes javascript form validation Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Practical Unit Testing with TestNG and Mockito this week in the Testing forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "javascript form validation" Watch "javascript form validation" New topic
Author

javascript form validation

Peter Straw
Ranch Hand

Joined: Jan 08, 2002
Posts: 78
Hi,
Please can you tell me how to get a simple form validation function to write the error to the page and not to an alert box.
Using document.write() in the javacsript function seems to write the error in a different page - I want the message to appear at the top of the form, and still show the original form elements, and position the cursor in the field that had illegal input.
Many thanks,
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15003
You would need to use innerHTML or layers,
here is some basic information:
http://www10.brinkster.com/a1ien51/JavaRanch/innerhtmltext.htm
There is also another way to do it and I have a link for it on my Basics Page on my site.

and also my validation utility. I have a version that writes messages on the screen, but it is not finished, it should be on the main page to my validation utility. I have not fixed it with CSS support and multiple validations per element.
Eric
Bear Bibeault
Author and opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 50677

As Eric pointed out, it's pretty simple to use the innerHTML property to add things to a page dynamically. I'd create an empty and hidden div where you want the error messages to appear, and upon detection of failure, fill the div with the messages and show the div.
Be aware however that innerHTML, even thought it works just fine in most moderne browsers, is not a w3c standard.
If you are concerned with standards compliance you need to go down the route of DOM manipulation, which is not only standards-compliant, but is also much more powerful (as well as confusing). Here is the DOM reference that I use.
Personally, I'd give the innerHTML route a try first. Them once that is working, decide if that's sufficient for your needs.
hth,
bear


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
 
 
subject: javascript form validation
 
Threads others viewed
How to find out which form generated errors ?
Form Validation and JavaScript
Execute javascript if there is no validation error
Display error message using validate?
JS Error ACCESS IS DENIED when submitting the form in jsp file through javascript
developer file tools