javasript problem - submiting

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

    javasript problem - submiting

    Please look at my code.
    I do validation of my form before I submit it.

    I want to be able to to press one form button without running validating
    script.
    I just want to go directly to my php script.

    I tried to do this
    onclick="docume nt.form1.submit ()" but than the button value is not posted
    and my php script is not working.

    Also I tried to remove the onSubmit handler on my form and than I add this
    to all my 3 buttons that will run with validation.


    <input type="button" name="select" value="save" on click="return
    check(this);doc ument.form1.sub mit()"It is not working I get error that Java
    does not support that object or method.Also the value save is not
    submitted.Is there any way to fix this


  • Jeff Thies

    #2
    Re: javasript problem - submiting

    > Please look at my code.[color=blue]
    > I do validation of my form before I submit it.[/color]

    Do this instead:

    <form onsubmit="retur n checkForm()" ...>

    Have checkForm return true if all is good and return false if there is
    an error.

    This will let you use a normal submit button and will let the form
    work if javascript is disabled.

    Jeff
    [color=blue]
    >
    > I want to be able to to press one form button without running validating
    > script.
    > I just want to go directly to my php script.
    >
    > I tried to do this
    > onclick="docume nt.form1.submit ()" but than the button value is not posted
    > and my php script is not working.
    >
    > Also I tried to remove the onSubmit handler on my form and than I add this
    > to all my 3 buttons that will run with validation.
    >
    > <input type="button" name="select" value="save" on click="return
    > check(this);doc ument.form1.sub mit()"It is not working I get error that Java
    > does not support that object or method.Also the value save is not
    > submitted.Is there any way to fix this[/color]

    Comment

    • Jeff Thies

      #3
      Re: javasript problem - submiting



      Jeff Thies wrote:[color=blue]
      >[color=green]
      > > Please look at my code.
      > > I do validation of my form before I submit it.[/color]
      >
      > Do this instead:
      >
      > <form onsubmit="retur n checkForm()" ...>[/color]

      I've reread your post and I think I misunderstood what you wanted. I
      think you want a submit button that bypasses the onsubmit validation

      Try this

      <form onsubmit="retur n checkForm()" ...>
      <input type="submit" value="normal" >
      <input type="submit" value="bypass" onclick="bypass ='1'">


      var bypass;
      function checkForm(){
      if(bypass){retu rn true;}
      ....
      normal form check code ...

      Jeff

      [color=blue]
      >
      > Have checkForm return true if all is good and return false if there is
      > an error.
      >
      > This will let you use a normal submit button and will let the form
      > work if javascript is disabled.
      >
      > Jeff
      >[color=green]
      > >
      > > I want to be able to to press one form button without running validating
      > > script.
      > > I just want to go directly to my php script.
      > >
      > > I tried to do this
      > > onclick="docume nt.form1.submit ()" but than the button value is not posted
      > > and my php script is not working.
      > >
      > > Also I tried to remove the onSubmit handler on my form and than I add this
      > > to all my 3 buttons that will run with validation.
      > >
      > > <input type="button" name="select" value="save" on click="return
      > > check(this);doc ument.form1.sub mit()"It is not working I get error that Java
      > > does not support that object or method.Also the value save is not
      > > submitted.Is there any way to fix this[/color][/color]

      Comment

      • Bartosz Wegrzyn

        #4
        Re: javasript problem - submiting

        I like the idea,but I am having problems with passing the bypass value to
        the script.

        I have onclick="bypass ='1'"
        and in my script I have

        var bypass
        if (bypass) {return true;}

        my function...

        shoutnot it be
        if (bypass==1) {return true;}

        Because this is not working.

        Bart,




















































        "Jeff Thies" <cyberjeff@spri ntmail.com> wrote in message
        news:3F5C03AB.6 7378A69@sprintm ail.com...[color=blue]
        >
        >
        > Jeff Thies wrote:[color=green]
        > >[color=darkred]
        > > > Please look at my code.
        > > > I do validation of my form before I submit it.[/color]
        > >
        > > Do this instead:
        > >
        > > <form onsubmit="retur n checkForm()" ...>[/color]
        >
        > I've reread your post and I think I misunderstood what you wanted. I
        > think you want a submit button that bypasses the onsubmit validation
        >
        > Try this
        >
        > <form onsubmit="retur n checkForm()" ...>
        > <input type="submit" value="normal" >
        > <input type="submit" value="bypass" onclick="bypass ='1'">
        >
        >
        > var bypass;
        > function checkForm(){
        > if(bypass){retu rn true;}
        > ...
        > normal form check code ...
        >
        > Jeff
        >
        >[color=green]
        > >
        > > Have checkForm return true if all is good and return false if there is
        > > an error.
        > >
        > > This will let you use a normal submit button and will let the form
        > > work if javascript is disabled.
        > >
        > > Jeff
        > >[color=darkred]
        > > >
        > > > I want to be able to to press one form button without running[/color][/color][/color]
        validating[color=blue][color=green][color=darkred]
        > > > script.
        > > > I just want to go directly to my php script.
        > > >
        > > > I tried to do this
        > > > onclick="docume nt.form1.submit ()" but than the button value is not[/color][/color][/color]
        posted[color=blue][color=green][color=darkred]
        > > > and my php script is not working.
        > > >
        > > > Also I tried to remove the onSubmit handler on my form and than I add[/color][/color][/color]
        this[color=blue][color=green][color=darkred]
        > > > to all my 3 buttons that will run with validation.
        > > >
        > > > <input type="button" name="select" value="save" on click="return
        > > > check(this);doc ument.form1.sub mit()"It is not working I get error that[/color][/color][/color]
        Java[color=blue][color=green][color=darkred]
        > > > does not support that object or method.Also the value save is not
        > > > submitted.Is there any way to fix this[/color][/color][/color]


        Comment

        • Jeff Thies

          #5
          Re: javasript problem - submiting



          Bartosz Wegrzyn wrote:[color=blue]
          >
          > I like the idea,but I am having problems with passing the bypass value to
          > the script.
          >
          > I have onclick="bypass ='1'"
          > and in my script I have
          >
          > var bypass
          > if (bypass) {return true;}
          >
          > my function...
          >
          > shoutnot it be
          > if (bypass==1) {return true;}[/color]

          Either way. 1 is true, 0 or undefined is false.

          Here's my little test page:

          <html>
          <body>
          <script type="text/javascript">
          var bypass;
          function checkForm(){
          if(bypass){aler t('go');return true;}else{
          alert('no go');return false;
          }
          }
          </script>
          <form onsubmit="retur n checkForm()" action="somewhe re.htm">
          <input type="submit" value="normal" >
          <input type="submit" value="bypass" onclick="bypass ='1'">
          </form>
          </body>
          </html>

          Jeff


          [color=blue]
          >
          > Because this is not working.
          >
          > Bart,
          >
          > "Jeff Thies" <cyberjeff@spri ntmail.com> wrote in message
          > news:3F5C03AB.6 7378A69@sprintm ail.com...[color=green]
          > >
          > >
          > > Jeff Thies wrote:[color=darkred]
          > > >
          > > > > Please look at my code.
          > > > > I do validation of my form before I submit it.
          > > >
          > > > Do this instead:
          > > >
          > > > <form onsubmit="retur n checkForm()" ...>[/color]
          > >
          > > I've reread your post and I think I misunderstood what you wanted. I
          > > think you want a submit button that bypasses the onsubmit validation
          > >
          > > Try this
          > >
          > > <form onsubmit="retur n checkForm()" ...>
          > > <input type="submit" value="normal" >
          > > <input type="submit" value="bypass" onclick="bypass ='1'">
          > >
          > >
          > > var bypass;
          > > function checkForm(){
          > > if(bypass){retu rn true;}
          > > ...
          > > normal form check code ...
          > >
          > > Jeff
          > >
          > >[color=darkred]
          > > >
          > > > Have checkForm return true if all is good and return false if there is
          > > > an error.
          > > >
          > > > This will let you use a normal submit button and will let the form
          > > > work if javascript is disabled.
          > > >
          > > > Jeff
          > > >
          > > > >
          > > > > I want to be able to to press one form button without running[/color][/color]
          > validating[color=green][color=darkred]
          > > > > script.
          > > > > I just want to go directly to my php script.
          > > > >
          > > > > I tried to do this
          > > > > onclick="docume nt.form1.submit ()" but than the button value is not[/color][/color]
          > posted[color=green][color=darkred]
          > > > > and my php script is not working.
          > > > >
          > > > > Also I tried to remove the onSubmit handler on my form and than I add[/color][/color]
          > this[color=green][color=darkred]
          > > > > to all my 3 buttons that will run with validation.
          > > > >
          > > > > <input type="button" name="select" value="save" on click="return
          > > > > check(this);doc ument.form1.sub mit()"It is not working I get error that[/color][/color]
          > Java[color=green][color=darkred]
          > > > > does not support that object or method.Also the value save is not
          > > > > submitted.Is there any way to fix this[/color][/color][/color]

          Comment

          • Lasse Reichstein Nielsen

            #6
            Re: javasript problem - submiting

            "Bartosz Wegrzyn" <blwegrzyn@lexo n.ws> writes:
            [color=blue]
            > I like the idea,but I am having problems with passing the bypass value to
            > the script.
            >
            > I have onclick="bypass ='1'"[/color]

            It really should be
            onclick="bypass =true;"
            No need to use the string '1' to represent true, when there is a perfectly
            good boolean value.
            [color=blue]
            > and in my script I have[/color]
            [color=blue]
            > var bypass[/color]

            The "var bypass" should be outside the function, as a global variable.
            You might want to initialize it:
            var bypass = false;
            It is not important, but it makes the code easier to read (you can see
            that it holds a boolean that is initially false).
            [color=blue]
            > if (bypass) {return true;}[/color]

            This should work. The condition of an if statement is converted to a
            boolean, and a non-empty string ('1') is converted to true.
            The values that are converted to false are
            false, null, undefined, "" (empty string), 0, and NaN (not-a-number).
            [color=blue]
            > my function...
            >
            > shoutnot it be
            > if (bypass==1) {return true;}[/color]

            No. If you want to compare to the string, it should be
            if (bypass == '1') {return true;}
            It is just simpler to use
            onclick="bypass = true;"
            and then just test
            if (bypass) {return true;}
            [color=blue]
            > Because this is not working.[/color]

            If it still isn't workig, try inserting an
            alert(bypass)
            just before the if statement, and see what value it has.

            /L
            --
            Lasse Reichstein Nielsen - lrn@hotpop.com
            Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
            'Faith without judgement merely degrades the spirit divine.'

            Comment

            • Vjekoslav Begovic

              #7
              Re: javasript problem - submiting

              "Bartosz Wegrzyn" <blwegrzyn@lexo n.ws> wrote in message
              news:IGR6b.2209 1$Ih1.8367612@n ewssrv26.news.p rodigy.com...[color=blue]
              > Please look at my code.
              > I do validation of my form before I submit it.
              >
              > I want to be able to to press one form button without running validating
              > script.
              > I just want to go directly to my php script.[/color]

              Try this:

              <form method="get" action="whateve r.php" onsubmit="retur n checkForm()">
              <input type="submit" value="normal" >
              <input type="button" value="bypass" onclick="this.f orm.submit()">
              </form>

              Vjekoslav


              Comment

              • Bartosz Wegrzyn

                #8
                Re: javasript problem - submiting

                On Mon, 08 Sep 2003 11:10:48 +0200, Lasse Reichstein Nielsen wrote:
                [color=blue]
                > "Bartosz Wegrzyn" <blwegrzyn@lexo n.ws> writes:
                >[color=green]
                >> I like the idea,but I am having problems with passing the bypass value to
                >> the script.
                >>
                >> I have onclick="bypass ='1'"[/color]
                >
                > It really should be
                > onclick="bypass =true;"
                > No need to use the string '1' to represent true, when there is a perfectly
                > good boolean value.
                >[color=green]
                >> and in my script I have[/color]
                >[color=green]
                >> var bypass[/color]
                >
                > The "var bypass" should be outside the function, as a global variable.
                > You might want to initialize it:
                > var bypass = false;
                > It is not important, but it makes the code easier to read (you can see
                > that it holds a boolean that is initially false).
                >[color=green]
                >> if (bypass) {return true;}[/color]
                >
                > This should work. The condition of an if statement is converted to a
                > boolean, and a non-empty string ('1') is converted to true.
                > The values that are converted to false are
                > false, null, undefined, "" (empty string), 0, and NaN (not-a-number).
                >[color=green]
                >> my function...
                >>
                >> shoutnot it be
                >> if (bypass==1) {return true;}[/color]
                >
                > No. If you want to compare to the string, it should be
                > if (bypass == '1') {return true;}
                > It is just simpler to use
                > onclick="bypass = true;"
                > and then just test
                > if (bypass) {return true;}
                >[color=green]
                >> Because this is not working.[/color]
                >
                > If it still isn't workig, try inserting an
                > alert(bypass)
                > just before the if statement, and see what value it has.
                >
                > /L[/color]

                Thanks its working.

                Comment

                • Bartosz Wegrzyn

                  #9
                  Re: javasript problem - submiting

                  On Mon, 08 Sep 2003 07:39:41 +0000, Jeff Thies wrote:
                  [color=blue]
                  >
                  >
                  > Bartosz Wegrzyn wrote:[color=green]
                  >>
                  >> I like the idea,but I am having problems with passing the bypass value to
                  >> the script.
                  >>
                  >> I have onclick="bypass ='1'"
                  >> and in my script I have
                  >>
                  >> var bypass
                  >> if (bypass) {return true;}
                  >>
                  >> my function...
                  >>
                  >> shoutnot it be
                  >> if (bypass==1) {return true;}[/color]
                  >
                  > Either way. 1 is true, 0 or undefined is false.
                  >
                  > Here's my little test page:
                  >
                  > <html>
                  > <body>
                  > <script type="text/javascript">
                  > var bypass;
                  > function checkForm(){
                  > if(bypass){aler t('go');return true;}else{
                  > alert('no go');return false;
                  > }
                  > }
                  > </script>
                  > <form onsubmit="retur n checkForm()" action="somewhe re.htm">
                  > <input type="submit" value="normal" >
                  > <input type="submit" value="bypass" onclick="bypass ='1'">
                  > </form>
                  > </body>
                  > </html>
                  >
                  > Jeff
                  >
                  >
                  >[color=green]
                  >>
                  >> Because this is not working.
                  >>
                  >> Bart,
                  >>
                  >> "Jeff Thies" <cyberjeff@spri ntmail.com> wrote in message
                  >> news:3F5C03AB.6 7378A69@sprintm ail.com...[color=darkred]
                  >> >
                  >> >
                  >> > Jeff Thies wrote:
                  >> > >
                  >> > > > Please look at my code.
                  >> > > > I do validation of my form before I submit it.
                  >> > >
                  >> > > Do this instead:
                  >> > >
                  >> > > <form onsubmit="retur n checkForm()" ...>
                  >> >
                  >> > I've reread your post and I think I misunderstood what you wanted. I
                  >> > think you want a submit button that bypasses the onsubmit validation
                  >> >
                  >> > Try this
                  >> >
                  >> > <form onsubmit="retur n checkForm()" ...>
                  >> > <input type="submit" value="normal" >
                  >> > <input type="submit" value="bypass" onclick="bypass ='1'">
                  >> >
                  >> >
                  >> > var bypass;
                  >> > function checkForm(){
                  >> > if(bypass){retu rn true;}
                  >> > ...
                  >> > normal form check code ...
                  >> >
                  >> > Jeff
                  >> >
                  >> >
                  >> > >
                  >> > > Have checkForm return true if all is good and return false if there is
                  >> > > an error.
                  >> > >
                  >> > > This will let you use a normal submit button and will let the form
                  >> > > work if javascript is disabled.
                  >> > >
                  >> > > Jeff
                  >> > >
                  >> > > >
                  >> > > > I want to be able to to press one form button without running[/color]
                  >> validating[color=darkred]
                  >> > > > script.
                  >> > > > I just want to go directly to my php script.
                  >> > > >
                  >> > > > I tried to do this
                  >> > > > onclick="docume nt.form1.submit ()" but than the button value is not[/color]
                  >> posted[color=darkred]
                  >> > > > and my php script is not working.
                  >> > > >
                  >> > > > Also I tried to remove the onSubmit handler on my form and than I add[/color]
                  >> this[color=darkred]
                  >> > > > to all my 3 buttons that will run with validation.
                  >> > > >
                  >> > > > <input type="button" name="select" value="save" on click="return
                  >> > > > check(this);doc ument.form1.sub mit()"It is not working I get error that[/color]
                  >> Java[color=darkred]
                  >> > > > does not support that object or method.Also the value save is not
                  >> > > > submitted.Is there any way to fix this[/color][/color][/color]

                  Thanks I put the bypass var inside the function.

                  Comment

                  Working...