javascript form validation which just doesnt work

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • x muzuo

    javascript form validation which just doesnt work

    Hi guys,
    I have got a prob of javascript form validation which just doesnt work
    with my ASP code. Can any one help me out please.

    Here is the code:

    ///////////////////////////////////////////////
    <%

    ntlogon = (Request.Server Variables("LOGO N_USER"))
    remotehost = (Request.Server Variables("REMO TE_HOST"))


    %>


    <body>

    <form name="form1" method="post" action="confadd idea.asp"
    onSubmit="retur n validate();">

    <font face=Verdana size=2>
    <i>Please note all fields marked with * are mandatory.</i>
    <i>Click on the <img src="iicon.gif" alt="" width=16px height=16px> icon
    for help with each field</i>
    <BR><BR>

    <table>

    <TR>
    <TD style="width=26 5px"> <font face=Verdana size=2>
    * First Name :
    <BR>
    <input name="f_name" size=25 maxlenght=50 class="myform">
    <img src="clear.jpg" border=0 width=23 height=20></a><br>
    <BR>
    * Surname Name :
    <BR>
    <input name="s_name" size=25 maxlenght=50
    class="myform" >
    <img src="clear.jpg" border=0 width=23
    height=20></a><br>
    <BR>

    * Email Address:
    <BR>

    <input name="e_address " size=25 maxlenght=50
    class="myform" >
    <a href="#" onmouseover="do Tooltip(event,0 )"
    onmouseout="hid eTip()">
    <img src="iicon.gif" border=0 width=16px
    height=16px></a><br><BR>


    * Telephone Number
    <BR>
    <input name="tel_numbe r" size=25 maxlenght=50
    class="myform" >
    <a href="#" onmouseover="do Tooltip(event,1 )"
    onmouseout="hid eTip()">
    <img src="iicon.gif" border=0 width=16px
    height=16px></a><br>
    <BR>

    * Employee ID :
    <BR>
    <input name="emp_id" size=25 maxlenght=50
    class="myform" >
    <a href="#" onmouseover="do Tooltip(event,2 )"
    onmouseout="hid eTip()">
    <img src="iicon.gif" border=0 width=16px
    height=16px></a><br>
    <br>
    <BR>
    </TD>
    <TD style="width=27 5px" valign="top" align="left">
    <font face=Verdana size=2>
    Job title :
    <BR>
    <input name="job_title " style="width=23 5px"
    maxlenght=50 class="myform" >
    <a href="#" onmouseover="do Tooltip(event,3 )"
    onmouseout="hid eTip()">
    <img src="iicon.gif" border=0 width=16px
    height=16px></a><br>
    <BR>



    </TD>
    </TR>
    <TD COLSPAN=2>
    <font face=Verdana size=2>
    * Suggestion Title :
    <BR>
    <input name="title_sug gestion"
    style="width=52 5px" maxlenght=50 class="myform" >
    <a href="#" onmouseover="do Tooltip(event,7 )"
    onmouseout="hid eTip()">
    <img src="iicon.gif" border=0 width=16px
    height=16px></a><br>
    <BR>

    * Suggestion :
    <BR>



    <TEXTAREA name="suggestio n" rows=15
    style="width=52 5px" size=250 maxlenght=250

    class="myform" ></textarea>
    <a href="#" onmouseover="do Tooltip(event,8 )"
    onmouseout="hid eTip()">
    <img src="iicon.gif" border=0 width=16px
    height=16px></a><br>
    <BR>

    <a href="#" onmouseover="do Tooltip(event,9 )"
    onmouseout="hid eTip()">
    <img src="iicon.gif" border=0 width=16px
    height=16px></a><br>
    <BR>

    </font>

    <input type="hidden" name="ntlogon"
    value="<%=ntlog on%>">
    <input type="hidden" name="remotehos t"
    value="<%=remot ehost%>">
    <input type="submit" value="Submit"
    onclick="this.f orm.submit();th is.disabled='tr ue';this.value= 'Please
    Wait..';">
    </td>

    </TABLE>
    </form>

    <div id="tipDiv" style="position :absolute; visibility:hidd en;
    z-index:100"></div>
    <iframe id="tipFrame" style="position :absolute; visibility:hidd en;
    z-index:90"></iframe>

    </body>
    </html>
    ////////////////////////////////////////////


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
  • Mick White

    #2
    Re: javascript form validation which just doesnt work

    x muzuo wrote:
    [color=blue]
    > Hi guys,
    > I have got a prob of javascript form validation which just doesnt work
    > with my ASP code. Can any one help me out please.
    >
    > Here is the code:
    >
    > <%
    > ntlogon = (Request.Server Variables("LOGO N_USER"))
    > remotehost = (Request.Server Variables("REMO TE_HOST"))
    > %>
    >
    > <body>
    > <form name="form1" method="post" action="confadd idea.asp"
    > onSubmit="retur n validate();">[/color]


    Where is "valdate()" defined?
    And your spelling of "maxlength" is wrong.

    [snip]

    Mick





    Comment

    • Jeff North

      #3
      Re: javascript form validation which just doesnt work

      On 15 Jan 2005 10:45:23 -0600, in comp.lang.javas cript x muzuo
      <muzuo173@yahoo .co.uk> wrote:
      [color=blue]
      >| Hi guys,
      >| I have got a prob of javascript form validation which just doesnt work
      >| with my ASP code. Can any one help me out please.
      >|
      >| Here is the code:
      >|
      >| ///////////////////////////////////////////////
      >| <%
      >| ntlogon = (Request.Server Variables("LOGO N_USER"))
      >| remotehost = (Request.Server Variables("REMO TE_HOST"))
      >| %>
      >|
      >| <body>
      >| <form name="form1" method="post" action="confadd idea.asp"
      >| onSubmit="retur n validate();">[/color]

      There are no javascript functions defined on/or linked to your page.

      [snip]

      ---------------------------------------------------------------
      jnorth@yourpant sbigpond.net.au : Remove your pants to reply
      ---------------------------------------------------------------

      Comment

      • x muzuo

        #4
        Re: javascript form validation which just doesnt work



        Hi guys,
        Thanks for your reply.
        sorry about the confusion, here is the validating code.

        with many thanks

        <<<snipped>>> >

        <script type="text/javascript">



        //Validating the form

        function validate(){
        if (document.form1 .f_name.value.l ength < 1) {
        alert("Please enter your first name.");
        return false;
        }
        if (document.form1 .s_name.value.l ength < 1) {
        alert("Please enter your surname.");
        return false;
        }
        if (document.form1 .e_address.valu e.length < 1) {
        alert("Please enter your first name.");
        return false;
        }
        if (document.form1 .f_name.value.l ength < 1) {
        alert("Please enter your emailaddress.") ;
        return false;
        }
        if (document.form1 .tel_number.val ue.length < 1) {
        alert("Please enter your telephone number.");
        return false;
        }
        if (document.form1 .emp_id.value.l ength < 1) {
        alert("Please enter your employee ID.");
        return false;
        }
        if (document.form1 .title_suggesti on.value.length < 1) {
        alert("Please enter your suggestion title.");
        return false;
        }
        if (document.form1 .suggestion.val ue.length < 3) {
        alert("Please enter your suggestion.");
        return false;
        }

        return ture;
        }


        <<<snipped>>> >



        *** Sent via Developersdex http://www.developersdex.com ***
        Don't just participate in USENET...get rewarded for it!

        Comment

        • x muzuo

          #5
          Re: javascript form validation which just doesnt work


          Hi guys,
          Thanks for your reply.
          sorry about the confusion, here is the validating code.

          with many thanks

          <<<snipped>>> >

          <script type="text/javascript">



          //Validating the form

          function validate(){
          if (document.form1 .f_name.value.l ength < 1) {
          alert("Please enter your first name.");
          return false;
          }
          if (document.form1 .s_name.value.l ength < 1) {
          alert("Please enter your surname.");
          return false;
          }
          if (document.form1 .e_address.valu e.length < 1) {
          alert("Please enter your first name.");
          return false;
          }
          if (document.form1 .f_name.value.l ength < 1) {
          alert("Please enter your emailaddress.") ;
          return false;
          }
          if (document.form1 .tel_number.val ue.length < 1) {
          alert("Please enter your telephone number.");
          return false;
          }
          if (document.form1 .emp_id.value.l ength < 1) {
          alert("Please enter your employee ID.");
          return false;
          }
          if (document.form1 .title_suggesti on.value.length < 1) {
          alert("Please enter your suggestion title.");
          return false;
          }
          if (document.form1 .suggestion.val ue.length < 3) {
          alert("Please enter your suggestion.");
          return false;
          }

          return ture;
          }


          <<<snipped>>> >




          *** Sent via Developersdex http://www.developersdex.com ***
          Don't just participate in USENET...get rewarded for it!

          Comment

          • Dr John Stockton

            #6
            Re: javascript form validation which just doesnt work

            JRS: In article <41ea7f32$1_1@1 27.0.0.1>, dated Sun, 16 Jan 2005
            08:50:26, seen in news:comp.lang. javascript, x muzuo
            <muzuo173@yahoo .co.uk> posted :
            [color=blue]
            > return ture;[/color]

            Quaint. Please post properly checked code, inserted by copy'n'paste.

            --
            © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
            <URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
            <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
            <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

            Comment

            • Grant Wagner

              #7
              Re: javascript form validation which just doesnt work

              "x muzuo" <muzuo173@yahoo .co.uk> wrote in message
              news:41e948a3$3 _2@127.0.0.1...[color=blue]
              > Hi guys,
              > I have got a prob of javascript form validation which just doesnt work
              > with my ASP code. Can any one help me out please.
              >
              > Here is the code:
              > <input type="submit" value="Submit"
              > onclick="this.f orm.submit();th is.disabled='tr ue';this.value= 'Please
              > Wait..';">[/color]

              You are programmaticall y calling Form#submit() from a submit button!

              Why would ever feel the need to do this, an <input type="submit" SUBMITS
              THE FORM. You don't need to include ONCLICK="...sub mit the form...", it
              ALREADY KNOWS HOW TO DO THAT.

              Not only that, but programmaticall y calling Form#submit() does _not_
              call the onsubmit event of the <form>, so your validation code _never
              runs_.

              <input type="submit" value="Submit"
              onclick="this.v alue='Please wait...';this.d isabled=true;re turn true;">

              Please note that the -disabled- property takes a boolean, not a string.

              By the way, if the user clicks Stop before the form gets navigated away
              from, or the form submission fails for some reason, you've left the user
              with a form that can not be re-submitted. One possible (but not
              necessarily the correct) solution to this is:

              <form name="myForm">
              <input type="submit" name="mySubmit"
              value="Submit"
              onclick="
              this.value='Ple ase wait...';
              this.disabled=t rue;
              var t = setTimeout(
              '(sub=document. forms[\'myForm\'].elements[\'mySubmit\']).disabled=fals e;sub.value=\'S ubmit\';',
              5000
              );
              return false;
              "[color=blue]
              >[/color]
              </form>

              This restores the submit button to working state after 5 seconds.

              --
              Grant Wagner <gwagner@agrico reunited.com>
              comp.lang.javas cript FAQ - http://jibbering.com/faq


              Comment

              Working...