Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > help required with validation

Reply
Thread Tools

help required with validation

 
 
hbm9966
Guest
Posts: n/a
 
      11-27-2005
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 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 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&nb sp&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>

 
Reply With Quote
 
 
 
 
Mick White
Guest
Posts: n/a
 
      11-27-2005
hbm9966 wrote:

> 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



 
Reply With Quote
 
 
 
 
Lee
Guest
Posts: n/a
 
      11-27-2005


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:

<script type="text/javascript">


>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()"

 
Reply With Quote
 
hbm9966
Guest
Posts: n/a
 
      11-28-2005
Lee,
Thanks for your comprehensive reply.
Couldn't have asked for more.
regards,

 
Reply With Quote
 
hbm9966
Guest
Posts: n/a
 
      11-28-2005
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

 
Reply With Quote
 
Dr John Stockton
Guest
Posts: n/a
 
      11-29-2005
JRS: In article <(E-Mail Removed) .com>
, dated Sun, 27 Nov 2005 22:28:29, seen in news:comp.lang.javascript,
hbm9966 <(E-Mail Removed)> posted :
>Actually I want to ensure that a valid e-mail address has been entered
>in the text field.
>Any suggestions will be appreciated.


There can be no way of doing that.

See <URL:http://www.merlyn.demon.co.uk/js-valid.htm#VEmA>.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      11-29-2005
Dr John Stockton wrote on 29 nov 2005 in comp.lang.javascript:

> JRS: In article <(E-Mail Removed) .com>
> , dated Sun, 27 Nov 2005 22:28:29, seen in news:comp.lang.javascript,
> hbm9966 <(E-Mail Removed)> posted :
>>Actually I want to ensure that a valid e-mail address has been entered
>>in the text field.
>>Any suggestions will be appreciated.

>
> 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.

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

 
Reply With Quote
 
Dr John Stockton
Guest
Posts: n/a
 
      11-30-2005
JRS: In article <Xns971DEFA783DA1eejj99@194.109.133.242>, dated Tue, 29
Nov 2005 22:33:30 local, seen in news:comp.lang.javascript, Evertjan.
<(E-Mail Removed)> posted :
>Dr John Stockton wrote on 29 nov 2005 in comp.lang.javascript:
>
>> JRS: In article <(E-Mail Removed) .com>
>> , dated Sun, 27 Nov 2005 22:28:29, seen in news:comp.lang.javascript,
>> hbm9966 <(E-Mail Removed)> posted :
>>>Actually I want to ensure that a valid e-mail address has been entered
>>>in the text field.
>>>Any suggestions will be appreciated.

>>
>> 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.


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.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demon.co.uk/news-use.htm> : about usage of News.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      11-30-2005
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.


--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create a VD with required properties on a required Web Server (Windows Advanced Server 2000 has 3 Web Servers) Just D. ASP .Net 0 03-10-2006 06:02 AM
required field validator doesn't show message on server validation z. f. ASP .Net 2 08-03-2004 02:20 PM
Problems with Validation Summary and Required Field Validator under Windows 2003 Alfonso Alvarez ASP .Net 0 05-13-2004 10:23 AM
help pls. textbox required only when checkbox is checked (help with validation) Emiliano ASP .Net Web Controls 2 10-16-2003 09:09 PM
Netscape required field validation problems Rick ASP .Net 3 07-07-2003 09:37 PM



Advertisments