I'm using the onClick event instead of the onSubmit and it seems PHP variables are not set correctly. Basiclly I have an input button with an onClick event. When the event is fired, a javascript function is executed where I do some checks and if everything is ok, the form is submitted. Then the problem is that when I check if the variable linked to the button is set the answer is false.

I'd appreciate if someone could help me ,
Albert

    Maybe some code so we can see what the problem is? Our telepathy is a lil off these days

      ----- onClick.php ------
      <HTML>
      <head>
      <script language="JavaScript">
      function check() {
      if (form1.nombre.value == "") {
      alert("obligatorio");
      result false;
      }
      form1.submit();
      }

      </head>
      <body>
      <FORM METHOD="POST" action="onClick2.php" name="form1">
      <input type="text" name="nombre" value="">
      <input type="button" name="aceptar" value="aceptar" onClick="check()">
      </form>
      </body>
      </html>

      ----- onClick2.php ------
      <?php printf(isset($aceptar)); ?>

        Try this:

        <HTML>
        <head>
        <script language="JavaScript">
        function check() {
          if (form1.nombre.value == "") {
            alert("obligatorio");
            return false;
          } else {
            return true;
          }
        }
        </script>
        </head>
        <body>
        <FORM METHOD="POST" action="onClick2.php" name="form1" onsubmit="return check();">
        <input type="text" name="nombre" value="">
        <input type="submit" name="aceptar" value="aceptar">
        </form>
        </body>
        </html>
        

          you do realies you dont have a </script> at the end????

            you're right the </script> should be there. Lost possibly during the copy/paste.

            I forgot to say that i've tried with the onSubmit event before and it worked fine. It's when using onClick that it doesn't work

              This just may be my being slow--But why do you have result false, instead of return false?

                I'm resposting the bit of code because it had quite a few mistakes because i was typing it.

                ----- onClick.php ------
                <HTML>
                <head>
                <script language="JavaScript">
                function check() {
                if (form1.nombre.value == "") {
                alert("obligatorio");
                return false;
                }
                form1.submit();
                }

                </head>
                <body>
                <FORM METHOD="POST" action="onClick2.php" name="form1">
                <input type="text" name="nombre" value="">
                <input type="button" name="aceptar" value="aceptar" onClick="check()">
                </form>
                </body>
                </html>

                ----- onClick2.php ------
                <?php printf(isset($aceptar)); ?>

                  Write a Reply...