help required with validation

H

hbm9966

Hi everybody
I have the following form written in html which I need to validate.
Have tried a few things, but the validation bit written in javascript
does not seem to be getting accessed at all.
Can somebody please tell me what is wrong.
Thanks and regards,
hbm9966


<html>
<head>
<title>Contact us - Right Investments India</title>
<link rel="shortcut icon" href="favicon.ico">
<META Name="description" Content="Maximise your investment returns
while investing minimum time and effort">
<META Name="keywords" Content="equity, shares, stocks, pms, "portfolio
management", newsletters, trading, "technical analysis", investing">

<SCRIPT LANGUAGE="JavaScript">
function validate() {
alert("reached validation");
if (document.formail.Reply-to.value = "Enter your e-mail address
here"){
alert("Please enter your correct e-mail address");
return false;
}
if (document.formmail.subject.value.length < 3){
alert("Please enter a subject for your mail");
return false;
}
if (document.formmail.Text.value.length<3){
alert("Cannot send blank message");
return false;
}
return true;
}
</SCRIPT>
</head>

<body>
<blockquote>
<table rules=none border=0>
<td width = "30%">
<a href=index.html><img src = ".\images\logo3.gif" border=0
alt="Home"></a>
<td width = "70%" align = right>
<hr size=3 color=gold width=100% align=right>
<center><h3>Contact &nbsp Us</h3></center>
<hr size=3 color=gold width=100% align=right>
<td width = "0%">
</tr>
</table>

<form name="formmail" method="post" action="./formmail.php"
onSubmit="validate();">
<input type=hidden name="recipient" value="(e-mail address removed)">
<b>From</b><br>
<input size=48 name="Reply-to" value="Enter your e-mail address here">
<br>
<input type=hidden name="email" value="(e-mail address removed)">
<b>Subject</b><br>
<input size=58 name="subject">
<br>
<b>Message</b><br>
<textarea cols=50 rows=6 name="Text"></textarea>
<input type="submit" value="Send">
<font
size=6>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</font>
<font size=1>&nbsp&nbsp&nbsp&nbsp</font>
<a href="javascript:history.back()"><img src=".\images\backarrow.gif"
border=0></a>
<input type="hidden" name="redirect" value=".\thankspage.html">
</form>
</blockquote>
</body>
</html>
 
M

Mick White

hbm9966 said:
Hi everybody
I have the following form written in html which I need to validate.
Have tried a few things, but the validation bit written in javascript
does not seem to be getting accessed at all.
Can somebody please tell me what is wrong.
Thanks and regards,
hbm9966


<html>
<head>
<title>Contact us - Right Investments India</title>
<link rel="shortcut icon" href="favicon.ico">
<META Name="description" Content="Maximise your investment returns
while investing minimum time and effort">
<META Name="keywords" Content="equity, shares, stocks, pms, "portfolio
management", newsletters, trading, "technical analysis", investing">

<SCRIPT LANGUAGE="JavaScript">
function validate() {
alert("reached validation");
if (document.formail.Reply-to.value = "Enter your e-mail address
here"){
alert("Please enter your correct e-mail address");
return false;
}
if (document.formmail.subject.value.length < 3){
alert("Please enter a subject for your mail");
return false;
}
if (document.formmail.Text.value.length<3){
alert("Cannot send blank message");
return false;
}
return true;
}
</SCRIPT>
</head>

<body>

[snip]
You can't use minus signs in js identifiers, you can however work
around it:

if (document.forms['formail'].elements['Reply-to'].value =
"Enter your e-mail address here")

But this is a strange way to validate the text field.
Mick
 
L

Lee

hbm9966 said:
Hi everybody
I have the following form written in html which I need to validate.

I see three problems:
<SCRIPT LANGUAGE="JavaScript">

1. This is not causing your problem, but should be fixed.
The "language" attribute is out-dated. Use:

function validate() {
alert("reached validation");
if (document.formail.Reply-to.value = "Enter your e-mail address
here"){

2. Two serious problems in the line above:
a) The equality comparison operator is "==", not "=".
As written, that is an assignment operation.
b) The left-hand side of that line contains an unintended
subtraction operation:

document.formail.Reply minus to.value

In the current form, as an assignment operation, the browser
is rejecting your entire function because you may not assign
a value to the result of a subtraction operation.
When you correct the operator, the function will be allowed,
so you will see the "alert()", but it will still cause an error
because it can't find the two operands for the subtraction.

You need to either change the name of the "Reply-to" field to
something that doesn't contain a minus sign, or use square-
bracket notation to refer to it:

document.formail.elements["Reply-to"].value

This is not the last problem, read on.

<form name="formmail" method="post" action="./formmail.php"
onSubmit="validate();">

3. In order for the onsubmit handler to prevent the form from
being submitted, it must return false. Your onsubmit handler
does not return any value.
Your "validate()" function returns a value, but it is not
really your onsubmit handler. It's just a function that is
called by your onsubmit handler.
The onsubmit handler is generated for you, using as the body
of the function the text of the "onsubmit" attribute of the
form tag. You want the body of that function to return the
value returned by your validate() function:

onsubmit="return validate()"
 
H

hbm9966

Hi Mick,
that's true.
Actually I want to ensure that a valid e-mail address has been entered
in the text field.
Any suggestions will be appreciated.
thanks and regards,
hbm9966
 
E

Evertjan.

Dr John Stockton wrote on 29 nov 2005 in comp.lang.javascript:
JRS: In article <[email protected]>
, dated Sun, 27 Nov 2005 22:28:29, seen in

There can be no way of doing that.

non-JS solution:

The OP could send an email to that address, and say "validated" if there is
no immediate error return mail.
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Tue, 29
Nov 2005 22:33:30 local, seen in Evertjan.
Dr John Stockton wrote on 29 nov 2005 in comp.lang.javascript:


non-JS solution:

The OP could send an email to that address, and say "validated" if there is
no immediate error return mail.

No.

But it could say "invalidated" if there is an immediate error return
mail.

But even that is not altogether trustworthy, since E-mails can be
rejected, perhaps immediately, on grounds other than address. I auto-
reject any mail *from* merlyn, since I know none is sent and some is
forged.

I lease all of merlyn demon co uk and dial up occasionally.

Mail for *@merlyn.dcu will be held at Demon until I next connect; and
cannot be rejected until then. If I were to alter my settings to
collect only mail for legitimate names, mail to others would be returned
by Demon after 30 days.

If I were on broadband there would still be a small delay, a few
minutes, I think.

While not connected to the Internet, I can change the list of addresses
valid at merlyn; and no-one can detect that from outside this room,
until I next connect.
 
E

Evertjan.

Dr John Stockton wrote on 30 nov 2005 in comp.lang.javascript:
While not connected to the Internet, I can change the list of addresses
valid at merlyn; and no-one can detect that from outside this room,
until I next connect.

I would not count that as an example of "valid", John.

Better perhaps,
is counting as INvalid,
all adresses that do not respond to a courteous request
to reply within 30 days?

This validation discussion is too dependent on definition,
as is found in many discussions.
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top