REQ: Could Someone assist in correcting this code ::::::::>>>(New JavaScript Student)

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

    REQ: Could Someone assist in correcting this code ::::::::>>>(New JavaScript Student)


    Hello! I am back with another question.

    Remember I am a new JavaScript student and I am aware that this code
    does not check for all the possibilities and that as a "NEW"
    JavaScript student I am not expected to check for everything.

    At any rate, the problem I am having with the following code is that
    it does not clear the fields once I press the SEND button. So can
    anyone here enlighten me as to what is causing the problem.

    *************** *************** *************** *************** **************



    <html>

    <head>
    <title>JavaScri pt Project</title>
    <SCRIPT LANGUAGE="JAVAS CRIPT">
    <!--Hide from old browsers
    function Validate(DataEn try) {
    // validate the Firstname
    var FstName=documen t.Register.Firs tName.value
    if (FstName == " ") {
    alert("Please enter your Firstname")
    document.Regist er.FirstName.va lue=" "
    document.Regist er.FirstName.fo cus()
    }
    else {

    // validate the Lastname
    var LstName=documen t.Register.Last Name.value
    if (LstName == " ") {
    alert("Please enter your Lastname")
    document.Regist er.LastName.val ue=" "
    document.Regist er.LastName.foc us()
    }
    else {

    // validate Age as be numeric
    var YearsOld=docume nt.Register.Age .value
    var YearsOld=parseI nt(YearsOld,10)
    if (isNaN(YearsOld )) {
    alert("Age is not numeric")
    document.Regist er.Age.value=" "
    document.Regist er.Age.focus();
    }
    else {

    // validate the @ sign and the period as being the fourth
    from the last character in an e-mail address
    var RegeMail=docume nt.Register.eMa il.value
    var atSign = RegeMail.indexO f("@")

    var Period=document .Register.eMail .value
    var PPeriod = Period.indexOf( '.');
    var LPeriod = Period.length - 4

    if (RegeMail == " " || atSign == -1 || LPeriod !=
    PPeriod) {
    alert("Please enter a valid e-mail address")
    document.Regist er.eMail.value = " "
    document.Regist er.eMail.focus( )
    }
    else {

    // validate the Gender in a drop down menu
    var sex=document.fo rms[0].Gender.selecte dIndex;
    if (sex==0) {
    alert("You must select your GENDER from the drop-down
    Menu.");
    document.forms[0].Gender.focus() ;
    }
    else
    {

    Gender_selectio n=document.form s[0].Gender.options[sex].value;
    return true;
    }
    }
    }
    }
    }
    }


    //-->
    </script>
    </head>

    <body>
    <FORM Name="Register" >
    <table border="0" width="90%">

    <!-- Begining of the first line of the form for entering data. -->
    <tr>
    <td>Enter Your Firstname :</td><td align="center">
    <Input Type="text" Name="FirstName " value=" "></td>
    <td>&nbspEnte r Your Age :</td> <td align="center">
    <Input Type="numeric" Name="Age" value=" "></td>
    <td align="center"> Select your : <SELECT NAME="Gender" SIZE=1 >
    <OPTION SELECTED VALUE=""> --- Select Gender ---
    <OPTION VALUE="Male">Ma le
    <OPTION VALUE="Female"> Female
    </SELECT>
    </td>
    </tr>
    <!-- ending of the first line of the form for entering data. -->

    <!-- Begining of the second line of the form for entering data. -->
    <tr>
    <td align="center"> Enter Your Lastname :</td><td align="center">
    <Input Type="text" Name="LastName" value=" "></td>
    <td align="center"> Enter Your Email Address :</td> <td
    align="center">
    <Input Type="text" Name="eMail" value=" "></td>
    <td align="right">< Input Type="button" Value="Send"
    onClick="Valida te(Register)">
    <Input
    Type="Reset">&n bsp&nbsp&nbsp&n bsp&nbsp&nbsp</td>
    </tr>
    <!-- ending of the second line of the form for entering data. -->

    </table>
    </form>
    </body>
    </html>
  • Lee

    #2
    Re: REQ: Could Someone assist in correcting this code ::::::::&gt;&gt ;&gt;(New JavaScript Student)

    Sue said:[color=blue]
    >
    >
    >Hello! I am back with another question.
    >
    >Remember I am a new JavaScript student and I am aware that this code
    >does not check for all the possibilities and that as a "NEW"
    >JavaScript student I am not expected to check for everything.
    >
    >At any rate, the problem I am having with the following code is that
    >it does not clear the fields once I press the SEND button. So can
    >anyone here enlighten me as to what is causing the problem.[/color]
    [color=blue]
    > <Input Type="button" Value="Send" onClick="Valida te(Register)">[/color]

    It's not clear why you expect the fields to be cleared.
    Your "Send" button doesn't actually send any data.
    It just executes your Validate() function.

    If you want it to send the data, you should use an input of
    type "submit", instead of "button", and instead of using the
    onclick event handler of the button, you should execute your
    Validate() function within the onsubmit event handler of the
    form.

    Comment

    • Michael Winter

      #3
      Re: REQ: Could Someone assist in correcting this code ::::::::&gt;&gt ;&gt;(New JavaScript Student)

      Lee wrote on 09 Dec 2003 at Tue, 09 Dec 2003 03:26:39 GMT:
      [color=blue]
      > Sue said:[/color]
      [color=blue][color=green]
      >> <Input Type="button" Value="Send"
      >> onClick="Valida te(Register)">[/color]
      >
      > If you want it to send the data, you should use an input of
      > type "submit", instead of "button", and instead of using the
      > onclick event handler of the button, you should execute your
      > Validate() function within the onsubmit event handler of the
      > form.[/color]

      You'll also want to make sure that you use the return keyword so that
      the result of the validation allows or cancels the submission.

      Mike

      --
      Michael Winter
      M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk")

      Comment

      • Sue

        #4
        Re: REQ: Could Someone assist in correcting this code ::::::::&gt;&gt ;&gt;(New JavaScript Student)

        On 8 Dec 2003 19:26:39 -0800, Lee <REM0VElbspamtr ap@cox.net> wrote:
        [color=blue]
        >Sue said:[color=green]
        >>
        >>
        >>Hello! I am back with another question.
        >>
        >>Remember I am a new JavaScript student and I am aware that this code
        >>does not check for all the possibilities and that as a "NEW"
        >>JavaScript student I am not expected to check for everything.
        >>
        >>At any rate, the problem I am having with the following code is that
        >>it does not clear the fields once I press the SEND button. So can
        >>anyone here enlighten me as to what is causing the problem.[/color]
        >[color=green]
        >> <Input Type="button" Value="Send" onClick="Valida te(Register)">[/color]
        >
        >It's not clear why you expect the fields to be cleared.
        >Your "Send" button doesn't actually send any data.
        >It just executes your Validate() function.
        >
        >If you want it to send the data, you should use an input of
        >type "submit", instead of "button", and instead of using the
        >onclick event handler of the button, you should execute your
        >Validate() function within the onsubmit event handler of the
        >form.[/color]


        Lee,

        I am having to take this JavaScript class over the Internet and other
        than the textbox, I have no help. Therefore, I am not sure about what
        you are talking about but I tried SUBMIT and it does clear the fields.
        However, if invalid data is entered and I press Send, all fields are
        cleared and the info has to be reentered.

        If you could make the changes to the code that you mentioned and
        post it I would greatly appreciate it.

        Thanks.

        Sue

        Comment

        • Brian

          #5
          Re: REQ: Could Someone assist in correcting this code ::::::::&gt;&gt ;&gt;(New JavaScript Student)


          "Sue" <SueWo@comcast. net > wrote in message
          news:6na89v4ubk 9jgrbg2n370ff29 1lsoc4krf@4ax.c om...[color=blue]
          > On 8 Dec 2003 19:26:39 -0800, Lee <REM0VElbspamtr ap@cox.net> wrote:
          >[color=green]
          > >Sue said:[color=darkred]
          > >>
          > >>
          > >>Hello! I am back with another question.
          > >>
          > >>Remember I am a new JavaScript student and I am aware that this code
          > >>does not check for all the possibilities and that as a "NEW"
          > >>JavaScript student I am not expected to check for everything.
          > >>
          > >>At any rate, the problem I am having with the following code is that
          > >>it does not clear the fields once I press the SEND button. So can
          > >>anyone here enlighten me as to what is causing the problem.[/color]
          > >[color=darkred]
          > >> <Input Type="button" Value="Send" onClick="Valida te(Register)">[/color]
          > >
          > >It's not clear why you expect the fields to be cleared.
          > >Your "Send" button doesn't actually send any data.
          > >It just executes your Validate() function.
          > >
          > >If you want it to send the data, you should use an input of
          > >type "submit", instead of "button", and instead of using the
          > >onclick event handler of the button, you should execute your
          > >Validate() function within the onsubmit event handler of the
          > >form.[/color]
          >
          >
          > Lee,
          >
          > I am having to take this JavaScript class over the Internet and other
          > than the textbox, I have no help. Therefore, I am not sure about what
          > you are talking about but I tried SUBMIT and it does clear the fields.
          > However, if invalid data is entered and I press Send, all fields are
          > cleared and the info has to be reentered.
          >
          > If you could make the changes to the code that you mentioned and
          > post it I would greatly appreciate it.
          >
          > Thanks.
          >
          > Sue
          >[/color]

          Hmmmm... Asking a newsgroup to fix your homework? Is that ethical? Part of
          the learning process is using resources to find solutions by your self....

          B


          Comment

          • Lee

            #6
            Re: REQ: Could Someone assist in correcting this code ::::::::&gt;&gt ;&gt;(New JavaScript Student)

            Brian said:[color=blue]
            >
            >
            >"Sue" <SueWo@comcast. net > wrote:[/color]
            [color=blue][color=green]
            >> If you could make the changes to the code that you mentioned and
            >> post it I would greatly appreciate it.[/color][/color]
            [color=blue]
            >Hmmmm... Asking a newsgroup to fix your homework? Is that ethical? Part of
            >the learning process is using resources to find solutions by your self....[/color]

            It's certainly more ethical than the students who try to pretend
            that it isn't homework: "My client would like a form that allows
            the visitor to type his name and have the message 'Hello, <name>!'
            appear in a popup alert box."

            I don't mind answering questions or giving tips, but I won't go
            so far as to complete the assignment.

            Here's a simple example of form validation. In production,
            I would use a regular expression to test to see if the field
            contains valid data, but that's beyond the scope of this
            assignment.

            <html>
            <head>
            <script type="text/javascript">
            function Validate(f){
            // f is a reference to the form to be validated.
            // This function returns true if all fields are valid
            // or false if any are invalid.

            if(f.FirstName. value==""){ // Note: no space between quotes
            alert("Please enter a value for First Name");
            f.FirstName.foc us();
            return false;
            }
            if(f.LastName.v alue==""){
            alert("Please enter a value for Last Name");
            f.LastName.focu s();
            return false;
            }

            return true; // All fields are valid.

            }
            </script>
            </head>
            <body>
            <form onsubmit="retur n Validate(this)" >
            First Name: <input name="FirstName "><br>
            Last Name: <input name="LastName" ><br>
            <input type="Submit" value="Send">
            </form>
            </body>

            Comment

            • Sue

              #7
              Re: REQ: Could Someone assist in correcting this code ::::::::&gt;&gt ;&gt;(New JavaScript Student)

              On 9 Dec 2003 09:05:31 -0800, Lee <REM0VElbspamtr ap@cox.net> wrote:
              [color=blue]
              >Brian said:[color=green]
              >>
              >>
              >>"Sue" <SueWo@comcast. net > wrote:[/color]
              >[color=green][color=darkred]
              >>> If you could make the changes to the code that you mentioned and
              >>> post it I would greatly appreciate it.[/color][/color]
              >[color=green]
              >>Hmmmm... Asking a newsgroup to fix your homework? Is that ethical? Part of
              >>the learning process is using resources to find solutions by your self....[/color]
              >
              >It's certainly more ethical than the students who try to pretend
              >that it isn't homework: "My client would like a form that allows
              >the visitor to type his name and have the message 'Hello, <name>!'
              >appear in a popup alert box."
              >
              >I don't mind answering questions or giving tips, but I won't go
              >so far as to complete the assignment.
              >
              >Here's a simple example of form validation. In production,
              >I would use a regular expression to test to see if the field
              >contains valid data, but that's beyond the scope of this
              >assignment.
              >[/color]



              Look guys I am not wanting to get into a ethical debate, but in most
              all of the computer related classes I have taken "in the classroom"
              the instructor has said, "I do not have time to provide all the help
              everyone needs so if you can help your neighbor please do so."

              Since I am not in class with classmates and the instructor stays
              confused as to who sent what email I thought I would ask for help
              here. I feel that if I were asking someone to do the complete
              assignment that would be unethical. As you can see I am not asking
              that. I am only asking for help on a small part and the code that I
              posted is probably only one-fourth of my overall project.

              Thanks for you help Lee. I will see if I can fix my problem.

              Sue



              Comment

              • Richard Cornford

                #8
                Re: REQ: Could Someone assist in correcting this code ::::::::&gt;&gt ;&gt;(New JavaScript Student)

                "Sue" <SueWo@comcast. net > wrote in message
                news:8ctctvcujq fvqe03e89k1j3ar e5hq7sn62@4ax.c om...
                <snip>[color=blue]
                >... and the instructor stays
                >confused as to who sent what email ...[/color]

                Given everything you have previously mentioned (such as the requirement
                to write e-mail address validators that have zero relation to how the
                task must be approached in the real world) it might be time to name the
                outfit providing this online "training". So they can be associated with
                the consequences of the quality of service they provide (particularly in
                google searches).

                Richard.


                Comment

                • Dennis M. Marks

                  #9
                  Re: REQ: Could Someone assist in correcting this code ::::::::&gt;&gt ;&gt;(New JavaScript Student)

                  In article <treatvo3lm5q53 6blj1qttq6e2ske urmhb@4ax.com>, Sue
                  <SueWo@comcast. net> wrote:
                  [color=blue]
                  > At any rate, the problem I am having with the following code is that
                  > it does not clear the fields once I press the SEND button. So can
                  > anyone here enlighten me as to what is causing the problem.
                  >
                  > *************** *************** *************** *************** **************
                  >
                  >
                  >
                  > <html>
                  >
                  > <head>
                  > <title>JavaScri pt Project</title>
                  > <SCRIPT LANGUAGE="JAVAS CRIPT">
                  > <!--Hide from old browsers
                  > function Validate(DataEn try) {
                  > // validate the Firstname
                  > var FstName=documen t.Register.Firs tName.value
                  > if (FstName == " ") {
                  > alert("Please enter your Firstname")
                  > document.Regist er.FirstName.va lue=" "
                  > document.Regist er.FirstName.fo cus()
                  > }
                  > else {[/color]
                  <SNIP>

                  You only clear the field if the field is blank. Move the end if bracket
                  up 2 lines.

                  --
                  Dennis M. Marks


                  -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
                  http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
                  -----== Over 100,000 Newsgroups - 19 Different Servers! =-----

                  Comment

                  Working...