Solved

how to write java script validate function

Posted on 2006-06-21
1
170 Views
Last Modified: 2010-05-18
Hi:

Currently I am working on an customer order form. The email address should be entered when the user submits. So I need add something like "input type=submit value=submit onclick="validate()"  " right? My question is how to write the validate() so that the user won't submit?
0
Comment
Question by:ly_uwo
1 Comment
 
LVL 14

Accepted Solution

by:
boonleng earned 200 total points
ID: 16951896
You need to return true or false in the javascript function.

Example:
<script>
function validate() {
    if (no error) {
        return true;
    } else {
        return false;
    }
}
</script>

<form onsubmit="return validate()">

Note: is best perform validation on onSubmit instead of onclick on the button. This is to cater for user press 'Enter' key.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how to access elements of included jsp  from parent jsp's save button 9 28
J2SE 5.0 metadata 1 67
grep code 4 205
JSONSerializer.toJSON in JSP generating error 8 88
After-hours service is a fact of life for most MSPs. While not the most pleasant aspect of the job, there are ways to make after-hours servicing a more profitable and organized enterprise.
Adults who share images on social media aren’t the only ones who need to worry about their privacy. Our culture’s tendency to share every move and celebration affects the privacy of our children, too.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question