problen with form validation not working

L

LRW

I'm trying to get the script to alert you of certain blank fields when
you submit the form, but it just doesn't work, and I can't see why. By
all appearances it should be working.
But I get no errors, and then you SUBMIT it just goes right on to the
next page completely bypassing the validation.
What am I doing wrong? What am I missing?
If someone could give me a clue, I'd appreciate it!

Below is the JS and the relavent parts of the form.
Thanks!!
Liam

<script language=JavaScript>
<!-- Begin
function ValidateE1() {
var FieldList = "";
if (document.f1.toemail.value.length < 2 ){
FieldList = "To Email\n";
}
if (document.f1.fromemail.value == "") {
FieldList = FieldList + "From Email\n";
}
if (document.f1.msg.value == "") {
FieldList = FieldList + "Message\n";
}
if (FieldList != "") {
alert("We did not get all the information we need from you.\n\n
Please fill in the following field(s):\n\n" + FieldList);
return false;
} else {
document.f1.submit();
}
}
// End -->
</script>
--SNIP--
<form name="f1" id="f1" method="post" action="emailerproc.bkk"
onSubmit="return ValidateE1();" >
--SNIP--
<td valign="top"><input name="toemail" id="toemail" type="text"
size="40">
<span class="labelBlue"><br>^-- Recipient's E-mail
address</span> </td>
--SNIP--
 
L

Lee

LRW said:
I'm trying to get the script to alert you of certain blank fields when
you submit the form, but it just doesn't work, and I can't see why. By
all appearances it should be working.
But I get no errors, and then you SUBMIT it just goes right on to the
next page completely bypassing the validation.
What am I doing wrong? What am I missing?
If someone could give me a clue, I'd appreciate it!

Below is the JS and the relavent parts of the form.

When posting code, please reformat it to use fewer columns.
You can see what happens to your code when I include it in
my reply:

<script language=JavaScript>
<!-- Begin
function ValidateE1() {
var FieldList = "";
if (document.f1.toemail.value.length < 2 ){
FieldList = "To Email\n";
}
if (document.f1.fromemail.value == "") {
FieldList = FieldList + "From Email\n";
}
if (document.f1.msg.value == "") {
FieldList = FieldList + "Message\n";
}
if (FieldList != "") {
alert("We did not get all the information we need from you.\n\n
Please fill in the following field(s):\n\n" + FieldList);
return false;
} else {
document.f1.submit();
}
}
// End -->
</script>


I don't know what system you're using that didn't flag the
error. Netscape 7 caught it right away.
The problem is that the first line of your alert contains an
unterminated string.
You can't just continue string literals from line to line.

Use something like:

alert("We did not get all the information we need from you.\n\n" +
"Please fill in the following field(s):\n\n" + FieldList);
 
L

LRW

Lee said:
When posting code, please reformat it to use fewer columns.
You can see what happens to your code when I include it in
my reply:

--SNIP--

I don't know what system you're using that didn't flag the
error. Netscape 7 caught it right away.
The problem is that the first line of your alert contains an
unterminated string.
You can't just continue string literals from line to line.

I couldn't see what you were talking about "fewer columns" until I
replied to your message. I'm using deja.com for my newsreader, and the
display shows nice and fine until I go into edit mode and it shows all
the extra columns. Sorry.

I was using Editplus (an elaborite notepad basically) to write with
and Avant browser (a glorified Internet Explorer) to view with. I'm
chagrined that Netscape told you what the problem was but neither
Avant nor IE told me.
What I did was go back through and deleted all blank spaces and
carriage returns and respaced and carriaged returned where necessary,
and that did it. What I found weird, is in several places when I'd
"delete" nothing would change and I'd have to delete once or twice
before the next character would move. Sort of like there were
invisible characters...like unintentional carriage returns perhaps.

But, it works great now! Thanks for the help!!
Liam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top