-
Return(false);
This is not ending the submission of the form. What am I missing?
Code:
<script language="JavaScript">
<!--
function addAnother(form){
if(form.ckAddAnother.checked)
{
if(form.LName.value != "")
{
LName = form.addITSS.LName;
}
else
{
alert("Plase fill in a last name!");
form.LName.focus();
return(false);
}
if(form.FName.value != "")
{
FName = form.FName.value;
}
else
{
alert("Plase fill in a first name!");
form.FName.focus();
return(false);
}
if(form.Region.value != "")
{
Region = form.Region.value;
}
else
{
alert("Plase fill in a region!");
form.Region.focus();
return(false);
}
if(form.administration.value != "")
{
administration = form.administration.value;
}
else
{
alert("Plase fill in an Administration!");
form.administration.focus();
return(false);
}
if(form.title.value != "")
{
title = form.title.value;
}
else
{
alert("Plase fill in a title!");
form.title.focus();
return(false);
}
}
return(true);
}
-->
</script>
-
do you have this in your form tag
onSubmit="return addAnother(this);"
-
this is what I have.
<form name="form" action="addITConf.asp" method="get" onSubmit="addAnother(this);">
-
sorry, I did not see the return part. thanks!!!
-
Well it works fine with the first if statement, but then if I fill in the last name, and do not fill in the first name, it will keep executing.
-
here's what i usually use
Code:
function validation(){
var msg='';
if(document.forms[0].fname.value==''){msg+='\n -First Name';}
if(document.forms[0].lname.value==''){msg+='\n -Last Name';}
if(document.forms[0].phone.value==''){msg+='\n -Phone #';}
if(document.forms[0].email.value==''){msg+='\n -Email';}
if(msg==''){
return true;
}else{
alert('You forgot to fill the following fields:\n\n' + msg);
return false;
}
}
and it works fine !
-
thanks, I will give it a shot. So does Javascript exit after that first if else statement?
-
no, cuz i check all the fields, then i check if i return true or false !
good luck ;)
-
i just looked at your function, and you have something wrong i think
the first check you put this
LName = form.addITSS.LName;
and all the other one you put
FName = form.FName.value;
should'nt be
FName = form.addITSS.FName;
-
that was my problem the whole time. Thanks!
-
You also misspelled Please in all of the "Plase fill in a ..." messages. Looks like another case of Copy|Paste gotcha. How many times have I done that myself? :rolleyes: