Hi,
I am new to javascript.
I have a form which I need to add an ajax loading image.
My question is how do I connect it to the camcheckrequired function so that if there is an error the image doesn't show?
Code:
<script language=javascript>
function camcheckrequired(theform) {
var returnval=true //by default, allow form submission
var checkit = document.getElementById('required_fields').value;
var requireds=theform.required_fields.value.split(";") //split using blank space as delimiter
for (i=0; i<requireds.length; i++){
var fieldnamez = requireds[i];
theform[fieldnamez].style.border = ''
if(fieldnamez.length > 1){
if (theform[fieldnamez].type=="text" || theform[fieldnamez].type=="textarea" || theform[fieldnamez].type=="file"){
if (theform[fieldnamez].value==""){ //if empty field
alert("Please make sure all required fields are filled out.") //alert error message
theform[fieldnamez].style.border = '1px solid red'
theform[fieldnamez].focus();
returnval=false //disallow form submission
break //end loop. No need to continue.
}
}
if (theform[fieldnamez].type=="select-one"){
if (theform[fieldnamez].value==""){
alert("Please make sure all required fields are filled out.") //alert error message
theform[fieldnamez].style.border = '1px solid red'
theform[fieldnamez].focus();
returnval=false //disallow form submission
break //end loop. No need to continue.
}
}
if(theform[fieldnamez].name=="emailaddr"){
var str = theform.emailaddr.value
var at="@"
var dot="."
var comma=","
var lat=str.indexOf(at)
var lstr=str.length
var ldot=str.indexOf(dot)
if (str.indexOf(at)==-1){
alert("Invalid E-mail Address")
theform.emailaddr.style.border = '1px solid red'
theform.emailaddr.focus();
returnval=false //disallow form submission
return false;
break //end loop. No need to continue.
}
if (str.indexOf(comma)>0){
alert("Invalid E-mail Address")
theform.emailaddr.style.border = '1px solid red'
theform.emailaddr.focus();
returnval=false //disallow form submission
return false;
break //end loop. No need to continue.
}
if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
alert("Invalid E-mail Address")
theform.emailaddr.style.border = '1px solid red'
theform.emailaddr.focus();
returnval=false //disallow form submission
return false;
break //end loop. No need to continue.
}
if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
alert("Invalid E-mail Address")
theform.emailaddr.style.border = '1px solid red'
theform.emailaddr.focus();
returnval=false //disallow form submission
return false;
break //end loop. No need to continue.
}
if (str.indexOf(at,(lat+1))!=-1){
alert("Invalid E-mail Address")
theform.emailaddr.style.border = '1px solid red'
theform.emailaddr.focus();
returnval=false //disallow form submission
return false;
break //end loop. No need to continue.
}
if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
alert("Invalid E-mail Address")
theform.emailaddr.style.border = '1px solid red'
theform.emailaddr.focus();
returnval=false //disallow form submission
return false;
break //end loop. No need to continue.
}
if (str.indexOf(dot,(lat+2))==-1){
alert("Invalid E-mail Address")
theform.emailaddr.style.border = '1px solid red'
theform.emailaddr.focus();
returnval=false //disallow form submission
return false;
break //end loop. No need to continue.
}
if (str.indexOf(" ")!=-1){
alert("Invalid E-mail Address")
theform.emailaddr.style.border = '1px solid red'
theform.emailaddr.focus();
returnval=false //disallow form submission
return false;
break //end loop. No need to continue.
}
}
}
theform[fieldnamez].style.border = ''
}
return returnval;
}
</script>
I can't post a link as it is in a password protected area.
Here is the full code including the form. It is the original without any changes.
There is too much text so I am placing the form code in the next post.
Code:
<script language=javascript>
function camcheckrequired(theform) {
var returnval=true //by default, allow form submission
var checkit = document.getElementById('required_fields').value;
var requireds=theform.required_fields.value.split(";") //split using blank space as delimiter
for (i=0; i<requireds.length; i++){
var fieldnamez = requireds[i];
theform[fieldnamez].style.border = ''
if(fieldnamez.length > 1){
if (theform[fieldnamez].type=="text" || theform[fieldnamez].type=="textarea" || theform[fieldnamez].type=="file"){
if (theform[fieldnamez].value==""){ //if empty field
alert("Please make sure all required fields are filled out.") //alert error message
theform[fieldnamez].style.border = '1px solid red'
theform[fieldnamez].focus();
returnval=false //disallow form submission
break //end loop. No need to continue.
}
}
if (theform[fieldnamez].type=="select-one"){
if (theform[fieldnamez].value==""){
alert("Please make sure all required fields are filled out.") //alert error message
theform[fieldnamez].style.border = '1px solid red'
theform[fieldnamez].focus();
returnval=false //disallow form submission
break //end loop. No need to continue.
}
}
if(theform[fieldnamez].name=="emailaddr"){
var str = theform.emailaddr.value
var at="@"
var dot="."
var comma=","
var lat=str.indexOf(at)
var lstr=str.length
var ldot=str.indexOf(dot)
if (str.indexOf(at)==-1){
alert("Invalid E-mail Address")
theform.emailaddr.style.border = '1px solid red'
theform.emailaddr.focus();
returnval=false //disallow form submission
return false;
break //end loop. No need to continue.
}
if (str.indexOf(comma)>0){
alert("Invalid E-mail Address")
theform.emailaddr.style.border = '1px solid red'
theform.emailaddr.focus();
returnval=false //disallow form submission
return false;
break //end loop. No need to continue.
}
if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
alert("Invalid E-mail Address")
theform.emailaddr.style.border = '1px solid red'
theform.emailaddr.focus();
returnval=false //disallow form submission
return false;
break //end loop. No need to continue.
}
if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
alert("Invalid E-mail Address")
theform.emailaddr.style.border = '1px solid red'
theform.emailaddr.focus();
returnval=false //disallow form submission
return false;
break //end loop. No need to continue.
}
if (str.indexOf(at,(lat+1))!=-1){
alert("Invalid E-mail Address")
theform.emailaddr.style.border = '1px solid red'
theform.emailaddr.focus();
returnval=false //disallow form submission
return false;
break //end loop. No need to continue.
}
if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
alert("Invalid E-mail Address")
theform.emailaddr.style.border = '1px solid red'
theform.emailaddr.focus();
returnval=false //disallow form submission
return false;
break //end loop. No need to continue.
}
if (str.indexOf(dot,(lat+2))==-1){
alert("Invalid E-mail Address")
theform.emailaddr.style.border = '1px solid red'
theform.emailaddr.focus();
returnval=false //disallow form submission
return false;
break //end loop. No need to continue.
}
if (str.indexOf(" ")!=-1){
alert("Invalid E-mail Address")
theform.emailaddr.style.border = '1px solid red'
theform.emailaddr.focus();
returnval=false //disallow form submission
return false;
break //end loop. No need to continue.
}
}
}
theform[fieldnamez].style.border = ''
}
return returnval;
}
</script>
<script type="text/javascript">
function loadSubmit() {
ProgressImage = document.getElementById('progress_image');
document.getElementById("progress").style.visibility = "visible";
setTimeout("ProgressImage.src = ProgressImage.src",100);
return true;
}
</script>
function camcheckrequired(theform) {
var returnval=true //by default, allow form submission
var checkit = document.getElementById('required_fields').value;
var requireds=theform.required_fields.value.split(";") //split using blank space as delimiter
for (i=0; i<requireds.length; i++){
var fieldnamez = requireds[i];
theform[fieldnamez].style.border = ''
if(fieldnamez.length > 1){
if (theform[fieldnamez].type=="text" || theform[fieldnamez].type=="textarea" || theform[fieldnamez].type=="file"){
if (theform[fieldnamez].value==""){ //if empty field
alert("Please make sure all required fields are filled out.") //alert error message
theform[fieldnamez].style.border = '1px solid red'
theform[fieldnamez].focus();
returnval=false //disallow form submission
break //end loop. No need to continue.
}
}
if (theform[fieldnamez].type=="select-one"){
if (theform[fieldnamez].value==""){
alert("Please make sure all required fields are filled out.") //alert error message
theform[fieldnamez].style.border = '1px solid red'
theform[fieldnamez].focus();
returnval=false //disallow form submission
break //end loop. No need to continue.
}
}
if(theform[fieldnamez].name=="emailaddr"){
var str = theform.emailaddr.value
var at="@"
var dot="."
var comma=","
var lat=str.indexOf(at)
var lstr=str.length
var ldot=str.indexOf(dot)
if (str.indexOf(at)==-1){
alert("Invalid E-mail Address")
theform.emailaddr.style.border = '1px solid red'
theform.emailaddr.focus();
returnval=false //disallow form submission
break //end loop. No need to continue.
}
if (str.indexOf(comma)>0){
alert("Invalid E-mail Address")
theform.emailaddr.style.border = '1px solid red'
theform.emailaddr.focus();
returnval=false //disallow form submission
break //end loop. No need to continue.
}
if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
alert("Invalid E-mail Address")
theform.emailaddr.style.border = '1px solid red'
theform.emailaddr.focus();
returnval=false //disallow form submission
break //end loop. No need to continue.
}
if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
alert("Invalid E-mail Address")
theform.emailaddr.style.border = '1px solid red'
theform.emailaddr.focus();
returnval=false //disallow form submission
break //end loop. No need to continue.
}
if (str.indexOf(at,(lat+1))!=-1){
alert("Invalid E-mail Address")
theform.emailaddr.style.border = '1px solid red'
theform.emailaddr.focus();
returnval=false //disallow form submission
break //end loop. No need to continue.
}
if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
alert("Invalid E-mail Address")
theform.emailaddr.style.border = '1px solid red'
theform.emailaddr.focus();
returnval=false //disallow form submission
break //end loop. No need to continue.
}
if (str.indexOf(dot,(lat+2))==-1){
alert("Invalid E-mail Address")
theform.emailaddr.style.border = '1px solid red'
theform.emailaddr.focus();
returnval=false //disallow form submission
break //end loop. No need to continue.
}
if (str.indexOf(" ")!=-1){
alert("Invalid E-mail Address")
theform.emailaddr.style.border = '1px solid red'
theform.emailaddr.focus();
returnval=false //disallow form submission
break //end loop. No need to continue.
}
}
}
theform[fieldnamez].style.border = ''
}
return returnval;
}
function loadSubmit(f) {
return camcheckrequired(f);
ProgressImage = document.getElementById('progress_image');
document.getElementById("progress").style.visibility = "visible";
setTimeout("ProgressImage.src = ProgressImage.src",100);
return true;
}
Bookmarks