javascript disable submit button until form is fully validated

Solutions on MaxInterview for javascript disable submit button until form is fully validated by the best coders in the world

showing results for - "javascript disable submit button until form is fully validated"
Mayron
08 Aug 2017
1function fieldValidation() {
2
3var name = document.forms['RegForm']['Name'].value;
4var address = document.forms['RegForm']['Address'].value;
5var email = document.forms['RegForm']['EMail'].value;
6var password = document.forms['RegForm']['Password'].value;
7var telephone = document.forms['RegForm']['Telephone'].value;
8var job = document.forms['RegForm']['Job'].value;
9var comment = document.forms['RegForm']['Comment'].value;
10var fullName = /^[a-zA-Z]+ [a-zA-Z]+$/;
11var phnFormat = /((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}/;
12
13if (name === '') {
14  alert('Please enter your name.'); 
15  return false;
16}
17
18if (!fullName.test(name)) {
19  alert('Please make sure we have your full name.');
20  return false;
21}
22
23if (address === '') { 
24  alert('Please enter your address.'); 
25  return false; 
26} 
27
28if (email === '') { 
29  alert('Please enter your e-mail address.'); 
30  return false; 
31} 
32
33if (password === '') { 
34  alert('Please enter a password.'); 
35  return false; 
36}   
37
38if (telephone === '') { 
39  alert('Please enter your telephone number.'); 
40  return false; 
41}
42
43if (!phnFormat.test(telephone)) {
44  alert('Please enter your phone number in the following format: (123) 555-1212)');
45  return false;
46}
47
48if (job.value === '') { 
49  alert('Please select a job choice.'); 
50  return false; 
51} 
52
53if (comment.value === '') { 
54  alert('Please enter a comment.'); 
55  return false; 
56}
57  return true;
58}