Answers for "Javascript prevent form submit until validation"

1

js stop form submit

<button type="submit" onclick="submitButtonClick(event)">Submit</button>
<script>
function submitButtonClick(event) {
		event.preventDefault();
		//other stuff you want to do instead...
} 
</script>
Posted by: Guest on July-27-2020
8

javascript prevent form submit

<form name="foo" onsubmit="return false">
Posted by: Guest on March-04-2020
0

javaScript disable submit button until form is fully validated

function fieldValidation() {

var name = document.forms['RegForm']['Name'].value;
var address = document.forms['RegForm']['Address'].value;
var email = document.forms['RegForm']['EMail'].value;
var password = document.forms['RegForm']['Password'].value;
var telephone = document.forms['RegForm']['Telephone'].value;
var job = document.forms['RegForm']['Job'].value;
var comment = document.forms['RegForm']['Comment'].value;
var fullName = /^[a-zA-Z]+ [a-zA-Z]+$/;
var phnFormat = /((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}/;

if (name === '') {
  alert('Please enter your name.'); 
  return false;
}

if (!fullName.test(name)) {
  alert('Please make sure we have your full name.');
  return false;
}

if (address === '') { 
  alert('Please enter your address.'); 
  return false; 
} 

if (email === '') { 
  alert('Please enter your e-mail address.'); 
  return false; 
} 

if (password === '') { 
  alert('Please enter a password.'); 
  return false; 
}   

if (telephone === '') { 
  alert('Please enter your telephone number.'); 
  return false; 
}

if (!phnFormat.test(telephone)) {
  alert('Please enter your phone number in the following format: (123) 555-1212)');
  return false;
}

if (job.value === '') { 
  alert('Please select a job choice.'); 
  return false; 
} 

if (comment.value === '') { 
  alert('Please enter a comment.'); 
  return false; 
}
  return true;
}
Posted by: Guest on November-21-2020

Code answers related to "Javascript prevent form submit until validation"

Code answers related to "Javascript"

Browse Popular Code Answers by Language