Solved

how to write java script validate function

Posted on 2006-06-21
1
172 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

First of all let me say that the only language that I speak is English, but in answering questions here I often come across people whose English skills are not the best and I’d like to be able to communicate better with them, and the following descr…
Compliance and data security require steps be taken to prevent unauthorized users from copying data.  Here's one method to prevent data theft via USB drives (and writable optical media).
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

615 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