PDA

View Full Version : Resolved multiple field checking



mcolton
08-23-2009, 11:29 AM
I have a lot of field checks on a form. If the user doesn't fill in required field and hits submit, he gets an error message popup for EVERY error. If the user didn't answer 9 questions, he gets 9 popups.

What I would like is: If the user doesn't fill in a required field and hits submit, he gets a popup error and focus is given to the field that needs to be input. That makes it a lot easier for the user.

I hope I explained this right. Below is partial code.



<script type="text/javascript">
function validate() {
mNv1=dogadoptionform.xname.value;
mNv2=dogadoptionform.xemail.value;
mNv3=dogadoptionform.xaddress.value;
mNv4=dogadoptionform.xcity.value;
.... lots more....

if (mNv1=='') {
alert('Name is required.');
event.returnValue=false;
}

if (mNv2=='') {
alert('Email is required.');
event.returnValue=false;
}
if (mNv3=='') {
alert('Address is required.');
event.returnValue=false;
}
if (mNv4=='') {
alert('City is required.');
event.returnValue=false;
}
.... lots more.....
</script>

kaos
08-23-2009, 04:40 PM
I'm a littile confused, will this script help?


<script language='javascript'>
function verifyMe(){
var msg='';

if(document.getElementById('name').value==''){
msg+='- Name\n\n';}

var email=document.getElementById('email').value;
if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))){
msg+='- Invalid Email Address: '+email+'\n\n';}

if(document.getElementById('email').value==''){
msg+='- Email\n\n';}

if(document.getElementById('subject').value=='ns'){
msg+='- Subject\n\n';}

if(document.getElementById('body').value==''){
msg+='- Message\n\n';}

if(msg!=''){
alert('The following fields are empty or invalid:\n\n'+msg);
return false
}else{
return true }

}
</script>

mcolton
08-24-2009, 06:17 PM
Thanks. It works great