Solved

how to write java script validate function

Posted on 2006-06-21
1
166 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Short answer to this question: there is no effective WiFi manager in iOS devices as seen in Windows WiFi or Macbook OSx WiFi management, but this article will try and provide some amicable solutions to better suite your needs.
In this article, I will show you HOW TO: Suppress Configuration Issues and Warnings Alert displayed in Summary status for ESXi 6.5 after enabling SSH or ESXi Shell.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now