Fields Need to be Filled Message to ONLY show upon submit when fields invalid

Started on the old forum in November 2011 · view the original in the archive · old links redirect here

No replies · 293 views · started 15 years ago · 1 min read

johnwboyd Junior · 12 posts #1

This is the code and "fields" is the tag I'm having an issue with since I don't want it to show when the user clicks submit if all the fields are valid:

// JavaScript Document function CheckTheForm() {

 var result = true;
var msg="";

document.getElementById('idmail').style.display="none"; document.getElementById('fields').style.display="none"; document.getElementById('First').style.color='#000000'; document.getElementById('maincontactemail').style.color='#000000'; document.getElementById('Last').style.color='#000000'; document.getElementById('refcode').style.color='#000000';

			    if (document.validate.First.value.length < 3) {
    document.validate.First.focus();
    document.getElementById('First').style.color="#FF3333";
    result = false;
}

		    if (document.validate.Last.value.length < 3) {
    document.validate.Last.focus();
    document.getElementById('Last').style.color="#FF3333";
    result = false;
}

			    if (document.validate.Last.value.length < 3) {
    document.validate.Last.focus();
    document.getElementById('Last').style.color="#FF3333";
    result = false;
}

			    if (document.validate.refcode.value.length < 3) {
    document.validate.refcode.focus();
    document.getElementById('refcode').style.color="#FF3333";
    result = false;
}

if (document.validate.maincontactemail.value.length < 7) {
    document.validate.maincontactemail.focus();
    document.getElementById('maincontactemail').style.color="#FF3333";
    result = false;

}
		
var emailID=document.validate.maincontactemail

if ((emailID.value==null)||(emailID.value=="")){
    document.validate.maincontactemail.focus();
    document.getElementById('maincontactemail').style.color="#FF3333";
    result = false;
}
if ((echeck(emailID.value)==false) && (emailID.value!='')){
    document.validate.maincontactemail.focus();
    document.getElementById('maincontactemail').style.color="#FF3333";
	document.getElementById('idmail').style.display="block";
    result = false;

		
} 


if(msg==""){
	document.getElementById('fields').style.display="block";
return result;
}{
alert(msg)
return result;

}
if(msg==""){
return result;
}{
alert(msg)
return result;
}

}

Write your reply now; next you create a free account (or sign in) and it is posted right away. Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close