Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / November 2005



Tip: Looking for answers? Try searching our database.

help required with validation

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
hbm9966 - 27 Nov 2005 15:27 GMT
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="postmaster@rightinvest.com">
<b>From</b><br>
<input size=48 name="Reply-to" value="Enter your e-mail address here">
<br>
<input type=hidden name="email" value="contactusform@rightinvest.com">
<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>
Mick White - 27 Nov 2005 16:20 GMT
> Hi everybody
> I have the following form written in html which I need to validate.
[quoted text clipped - 35 lines]
>
> <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
hbm9966 - 28 Nov 2005 06:28 GMT
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
Dr John Stockton - 29 Nov 2005 20:14 GMT
JRS:  In article <1133159309.627350.303440@g47g2000cwa.googlegroups.com>
, dated Sun, 27 Nov 2005 22:28:29, seen in news:comp.lang.javascript,
hbm9966 <hormuzmaloo@yahoo.com> 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>.

Signature

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

Evertjan. - 29 Nov 2005 22:33 GMT
Dr John Stockton wrote on 29 nov 2005 in comp.lang.javascript:

> JRS:  In article <1133159309.627350.303440@g47g2000cwa.googlegroups.com>
> , dated Sun, 27 Nov 2005 22:28:29, seen in news:comp.lang.javascript,
[quoted text clipped - 4 lines]
>
> 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.

Signature

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

Dr John Stockton - 30 Nov 2005 15:57 GMT
JRS:  In article <Xns971DEFA783DA1eejj99@194.109.133.242>, dated Tue, 29
Nov 2005 22:33:30 local, seen in news:comp.lang.javascript, Evertjan.
<exjxw.hannivoort@interxnl.net> posted :
>Dr John Stockton wrote on 29 nov 2005 in comp.lang.javascript:
>
[quoted text clipped - 11 lines]
>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.

Signature

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

Evertjan. - 30 Nov 2005 18:40 GMT
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.

Signature

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

Lee - 27 Nov 2005 16:41 GMT
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()"
hbm9966 - 28 Nov 2005 06:26 GMT
Lee,
Thanks for your comprehensive reply.
Couldn't have asked for more.
regards,
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.