Praveen Chinthala
how to validate all form field values at once.
1 Answer(s)      3 years and 3 months ago
Posted in : JavaScript Questions

how to validate all form field values at once. condition:no form field shold contain sometext("--select--")

Advertisement
View Answers

January 14, 2012 at 5:28 PM


<html>
<center>
<h2>JOIN US</h2>
</center>
<script>
function ValidPhone(aphone)
{
    var valid = "0123456789";
         if(aphone=="")
         {
    alert ("This field is required. Please enter phone number without dashes!")
         return false
         }
         if(aphone.length !=10)
         {
    alert("Invalid phone number length! Please try again.")
         return false
         }
         for (var i=0; i < aphone.length; i++)
         {
         temp = "" + aphone.substring(i, i+1);
         if (valid.indexOf(temp) == "-1")
         {
    alert("Invalid characters in your field. Please try again.")
          return false;
         }

    }
    return true
}
function validate(){
var fname=document.form.fname.value;
var lname=document.form.lname.value;
var email=document.form.email.value;
var phone=document.form.contactNo.value;
var address=document.form.address.value;
var city=document.form.city.value;
var atpos=email.indexOf("@");
var dotpos=email.lastIndexOf(".");
if(fname==""){
    alert("Please enter first name!");
    document.form.fname.focus();
    return false;
}
 if(lname==""){
    alert("Please enter last name!");
    document.form.lname.focus();
    return false;
}
 if(email==""){
    alert("Please enter email id!");
    document.form.email.focus();
    return false;
  }

if (atpos<1 || dotpos<atpos+2 || dotpos+2>=email.length)
  {
  alert("Invalid Email ID");
  return false;
  }
   if(!ValidPhone(phone))
         {
         document.form.contactNo.focus()
         return false
         }
         if(address==""){
    alert("Please enter address!");
    document.form.address.focus();
    return false;
}
if(city==""){
    alert("Please enter city!");
    document.form.city.focus();
    return false;
}
return true;

}
</script>

<form name="form" method="post" action="insert.jsp" onsubmit="return validate();">
<center>
<table>
<tr><td> First Name</td><td><input type="text" name="fname"></td></tr>
<tr><td> Last Name</td><td><input type="text" name="lname"></td></tr>
<tr><td> Email</td><td><input type="text" name="email"></td></tr>
<tr><td> Contact No</td><td><input type="text" name="contactNo"></td></tr>
<tr><td> Address</td><td><input type="text" name="address"></td></tr>
<tr><td> City</td><td><input type="text" name="city"></td></tr>

<tr><td><input type="submit" value="Save"></td><td><input type="reset" value="Reset"></td></tr>
</table>
</center>
</form>
</html>









Related Tutorials/Questions & Answers:
how to validate all form field values at once.
how to validate all form field values at once.  how to validate all form field values at once. condition:no form field shold contain sometext("--select
How to validate a form - JSP-Servlet
How to validate a form   Dear Sir, I have a one jsp... want to validate a form1 i.e in form1 i have a text field for a Id values .If i submit a form without any Id values in a text field i have to get an aleert message
Advertisements
how to validate values in the dynamically created textboxes?
how to validate values in the dynamically created textboxes?  how to validate values in the dynamically created textboxes in HTML using javascript...;'; BODY.appendChild(TR1); n++; } function validate(form1) { //What to code here } <
validate text field iPhone
validate text field iPhone  i got two different UITextfield in my iPhone application for user login. Just wondering how to validate
How to validate a form in action class and forward errors to the jsp in struts?
How to validate a form in action class and forward errors to the jsp in struts?  How to validate a form in action class and forward errors to the jsp in struts
form field issue
form field issue  how to set the values in form field and form field drop down (doc 2007) using Apache poi
insertin form data into databse and blank all form field when click on submit button
insertin form data into databse and blank all form field when click on submit button  sir, i useing the jsp. i want insert form data into Ms-Access database when click on submit button and blank all form field after inserting
how to validate e,ail id and phne number in student form
how to validate e,ail id and phne number in student form  how to validate e,ail id and phne number in student form   Hi Friend, Visit Here Thanks
how to validate e,ail id and phne number in student form
how to validate e,ail id and phne number in student form  how to validate e,ail id and phne number in student form   Hi Friend, Visit Here Thanks
How do i validate form using javascript and send data to database?
How do i validate form using javascript and send data to database?  I need a "JOIN US" form that can validate using javascript and be able to connect...=="") { alert ("This field is required. Please enter phone number without dashes
how to validate e,ail id and phne number in student form
how to validate e,ail id and phne number in student form  how to validate e,ail id and phne number in student form   Hi Friend, Try the following code: <html> <script> function validate(){ var ph
the focus to the first form field
the focus to the first form field   How do I set the focus to the first form field
focus to the first form field
focus to the first form field  How do I set the focus to the first form field
focus to the first form field
focus to the first form field  How do I set the focus to the first form field
how to get a values from a multipart/form-data - JSP-Servlet
how to get a values from a multipart/form-data  Dear sir , I used your code for getting a values,i used the fllowing function... ,matter,file field values but not status and from field i am getting null
spring form field clearence
spring form field clearence  hi, I have spring form application in which i have security question and answer field for answer field validation after giving wrong format validation occurs but the field remains in that text field
form validate and perfom action immediatly
form validate and perfom action immediatly  This is ok, but what i'm looking for is whenever a user input different data his input has to validate..." for Age in a form then he needs to redirect him to some web page like
how to update values of a html form into an excel table using java servlets?
how to update values of a html form into an excel table using java servlets?  i have written a java servlet program, which has a html form to be filled. after filling the form the servlet generates a receipt and the values should
how to load values of html form into an excel table using java servlet?
how to load values of html form into an excel table using java servlet?   i have written a java servlet program, which has a html form to be filled. after filling the form the servlet generates a receipt and the values should
How to insert and update all column values of database from jtable.
How to insert and update all column values of database from jtable.  ... ,update,delete database values from jtable only so i added three buttons add... of particular row is not getting added into the database whereas all other records
How to insert and update all column values of database from jtable.
How to insert and update all column values of database from jtable.  ... ,update,delete database values from jtable only so i added three buttons add,update... row is not getting added into the database whereas all other records are getting
How to insert and update all column values of database from jtable.
How to insert and update all column values of database from jtable.  ... ,update,delete database values from jtable only so i added three buttons add,update... row is not getting added into the database whereas all other records are getting
How to retrieve array values from html form to jsp?
How to retrieve array values from html form to jsp?  Hi! I am... it into jsp. Means i just want to retrieve values from html form containing array... sample code for how to retrive array values from html to jsp.   hi friend
how to pass form values from javascript of html page to jsp page
how to pass form values from javascript of html page to jsp page   ... the geocode and tries to return the lattitude and longitude .But my question is how to submit all the form values with lattitude and longitude returned from
clearing text field in spring form
clearing text field in spring form  hi, I have spring form in that i have security question dropdown field and security answer text field ,when i submitted form with errors the answers text field value should be clear, for this i
Login form in Struts2 version 2.3.16
How to create Login Form in Struts2? In this video tutorial I am explaining... of creating the Login form in Struts 2: In the above video you will find all... how to make a login form in Struts2. Check more Struts 2 tutorials. Download
how to validate the email login
how to validate the email login  // JavaScript Document JOIN US... characters in your field. Please try again.") return false; } } return true } function validate(){ var fname=document.form.fname.value
how can retrieve more than one values in text field using ajax?
how can retrieve more than one values in text field using ajax?  im using php and ajax. Problem is that i want to search seat numbers bases of batch... field so what i do? entermarks.php <div align="left"><strong>
form values in java script - Struts
form values in java script  how to get form values in java script functions with struts1.1
how to validate duplicate records in struts1
how to validate duplicate records in struts1  Hi, After submitting the form i have to validate the email id. If already exists in database i have to display an error message saying that email id already exist
how to validate duplicate records in struts1
how to validate duplicate records in struts1  Hi, After submitting the form i have to validate the email id. If already exists in database i have to display an error message saying that email id already exist