help required with validation

Discussion in 'Javascript' started by hbm9966, Nov 27, 2005.

  1. hbm9966

    hbm9966 Guest

    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="">
    <b>From</b><br>
    <input size=48 name="Reply-to" value="Enter your e-mail address here">
    <br>
    <input type=hidden name="email" value="">
    <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>
    hbm9966, Nov 27, 2005
    #1
    1. Advertising

  2. hbm9966

    Mick White Guest

    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
    Mick White, Nov 27, 2005
    #2
    1. Advertising

  3. hbm9966

    Lee Guest

    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()"
    Lee, Nov 27, 2005
    #3
  4. hbm9966

    hbm9966 Guest

    Lee,
    Thanks for your comprehensive reply.
    Couldn't have asked for more.
    regards,
    hbm9966, Nov 28, 2005
    #4
  5. hbm9966

    hbm9966 Guest

    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
    hbm9966, Nov 28, 2005
    #5
  6. JRS: In article <>
    , dated Sun, 27 Nov 2005 22:28:29, seen in news:comp.lang.javascript,
    hbm9966 <> 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.
    Dr John Stockton, Nov 29, 2005
    #6
  7. hbm9966

    Evertjan. Guest

    Dr John Stockton wrote on 29 nov 2005 in comp.lang.javascript:

    > JRS: In article <>
    > , dated Sun, 27 Nov 2005 22:28:29, seen in news:comp.lang.javascript,
    > hbm9966 <> 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)
    Evertjan., Nov 29, 2005
    #7
  8. JRS: In article <Xns971DEFA783DA1eejj99@194.109.133.242>, dated Tue, 29
    Nov 2005 22:33:30 local, seen in news:comp.lang.javascript, Evertjan.
    <> posted :
    >Dr John Stockton wrote on 29 nov 2005 in comp.lang.javascript:
    >
    >> JRS: In article <>
    >> , dated Sun, 27 Nov 2005 22:28:29, seen in news:comp.lang.javascript,
    >> hbm9966 <> 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.
    Dr John Stockton, Nov 30, 2005
    #8
  9. hbm9966

    Evertjan. Guest

    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)
    Evertjan., Nov 30, 2005
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rick
    Replies:
    3
    Views:
    404
    Chris Becker
    Jul 7, 2003
  2. Alfonso Alvarez
    Replies:
    0
    Views:
    586
    Alfonso Alvarez
    May 13, 2004
  3. z. f.
    Replies:
    2
    Views:
    466
    Thomas Dodds
    Aug 3, 2004
  4. Just D.
    Replies:
    0
    Views:
    437
    Just D.
    Mar 10, 2006
  5. Emiliano
    Replies:
    2
    Views:
    314
    Rajesh.V
    Oct 16, 2003
Loading...

Share This Page