Loading ...
Sorry, an error occurred while loading the content.
 

Re: Mozilla document.forms.submit() problem

Expand Messages
  • Chuck
    Jon, thanks for your reply. I may have just resolved the issue, but will have to wait until Monday when I can verify on clients pc. As to your question, no,
    Message 1 of 4 , Jun 5, 2004
      Jon, thanks for your reply. I may have just resolved the issue, but
      will have to wait until Monday when I can verify on clients' pc.

      As to your question, no, I was calling the submit method in the form:
      document.formname.submit();
      (had also tried the document.forms["formname"].submit(); format, with
      the same, expected results...but tried just in case)

      If it's still an issue, I'll elaborate so we can all scratch our
      heads. Otherwise, I'll just post a synopsis of the
      problem/resolution. (Could be simply a "not-so-dumb goof". That is,
      confusing the browser when I knew better, but in a not necessarily
      obvious way.)



      --- In javascript_official@yahoogroups.com, Jon Stephens <jon@h...> wrote:
      > Are you actually trying to call this as
      >
      > document.forms.submit()
      >
      > ?
      >
      > submit() is a method of a single form object, not of the forms
      collection.
      >
      > e.g.
      >
      > <form method="POST" action="page.php">
      > ...
      > <input type="button" name="mybutton" onclick="this.form.submit();"
      value="Submit">
      > </form>
      >
      > or
      >
      > <form name="myForm" method="POST" action="page.php">
      > ...
      > </form>
      > <p><a href="javascript:document.myForm.submit();">Submit</a></p>
      >
      > Not sure I understand exactly what your problem is, other than that
      -- can you elaborate or
      > provide a link or source code?
      >
      > Are you looking to do something like this?
      >
      > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
      > "http://www.w3.org/TR/html4/loose.dtd">
      > <html>
      > <head>
      > <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
      > <title></title>
      > </head>
      > <body>
      >
      > <form action="<?php echo $PHP_SELF; ?>" method="POST">
      > <?php
      > for($i = 1; $i <= 5; $i++)
      > {
      > echo " <p>$i. <input type=\"submit\" name=\"submit$i\"
      value=\"Button #$i\"></p>\n";
      > }
      > ?>
      > </form>
      >
      > <?php
      > foreach($_POST as $key => $value)
      > {
      > if(strpos($key, "submit") !== FALSE)
      > {
      > echo "<p>You pressed $value.</p>";
      > break;
      > }
      > }
      > ?>
      >
      > </body>
      > </html>
      >
      > > Date: Fri, 04 Jun 2004 03:10:44 -0000
      > > From: "Chuck" <caharris@r...>
      > > Subject: Mozilla document.forms.submit() problem
      > >
      > > Hi all,
      > > Maybe someone here can answer my question. (I may have missed
      > > something somewhere, but so far I haven't found anything with LOTS of
      > > searching.)
      > >
      > > background:
      > > I've got an app (Linux/Mozilla 1.0.1/Apache/PHP/mySQL/HTML/Javascript)
      > > to be run on (WinXP/IE 6/Apache/PHP/etc.)
      > >
      > > problem:
      > > (Due to browser differences, I've had a few "issues" with IE, all of
      > > which have been overcome except this one.)
      > >
      > > The <BUTTON...> tag works completely different in IE from Mozilla, so
      > > I have to resort to the older <INPUT type=...> format for a menu form,
      > > and use an 'onclick=' javascript function that, at its end, calls the
      > > document.forms.submit() method. HOWEVER, Mozilla doesn't pass any
      > > POST fields for some reason. Everything works fine with the
      > > <BUTTON...> tags (to the point I've got things), but it fails with the
      > > <INPUT...> tags using the submit() method.
      > >
      > > NOTE: under IE, the text between the <BUTTON></BUTTON> tags is used
      > > for the POST variable, instead of the 'value="foo"' attribute (like
      > > it's supposed to do).
      > >
      > > Any ideas?
      > >
      > > (The only thing I can think of is, in my PHP code, to check for BOTH
      > > values--the ones that Mozilla and IE will pass--but that is so
      > > inefficient!)
      > >
      > > Thanks in advance.
    • Chuck
      Things are okay now, Jon. The issue is one of browser behaviour differences, but knowing that makes all the difference in the world. Synopsis: Here s the
      Message 2 of 4 , Jun 8, 2004
        Things are okay now, Jon. The issue is one of browser behaviour
        differences, but knowing that makes all the difference in the world.

        Synopsis:
        Here's the format that works under Mozilla:
        <button type="submit" name="choice" value="val1"...>label1</button>
        <button type="submit" name="choice" value="val2"...>label2</button>
        <button type="submit" name="choice" value="val3"...>label3</button>
        ...(ad infinitum)
        and, I get only the desired value of the button selected (i.e., "val1"
        OR "val2" OR "val3", etc.), along with some hidden fields that I need.

        Under IE, the above submits ALL button labels ("label1" AND "label2",
        etc.,) for buttons not set as disabled instead of the appropriate value.

        Now, when I changed the code to this:
        <input type="button" name="val1" value="label1" onClick=setChoice(x)>
        <button type="submit" name="choice" value="val2"...>label2</button>
        <button type="submit" name="choice" value="val3"...>label3</button>
        ...(ad infinitum)

        (the thinking of incremental debug testing, make minimal changes and
        test the change) didn't work properly under Mozilla because I had
        mixed the "submit" types.

        On a thought, I went ahead and changed ALL (sigh...) of the <button..>
        tags to the <input..> tags and everything worked okay (on both Mozilla
        and IE). So much for incremental system changes (which work just fine
        in languages like C/C++, Perl, etc.)

        Lesson learned and issue resolved.



        --- In javascript_official@yahoogroups.com, "Chuck" <caharris@r...> wrote:
        > Jon, thanks for your reply. I may have just resolved the issue, but
        > will have to wait until Monday when I can verify on clients' pc.
        >
        > As to your question, no, I was calling the submit method in the form:
        > document.formname.submit();
        > (had also tried the document.forms["formname"].submit(); format, with
        > the same, expected results...but tried just in case)
        >
        > If it's still an issue, I'll elaborate so we can all scratch our
        > heads. Otherwise, I'll just post a synopsis of the
        > problem/resolution. (Could be simply a "not-so-dumb goof". That is,
        > confusing the browser when I knew better, but in a not necessarily
        > obvious way.)
        >
        >
        >
        > --- In javascript_official@yahoogroups.com, Jon Stephens <jon@h...>
        wrote:
        > > Are you actually trying to call this as
        > >
        > > document.forms.submit()
        > >
        > > ?
        > >
        > > submit() is a method of a single form object, not of the forms
        > collection.
        > >
        > > e.g.
        > >
        > > <form method="POST" action="page.php">
        > > ...
        > > <input type="button" name="mybutton" onclick="this.form.submit();"
        > value="Submit">
        > > </form>
        > >
        > > or
        > >
        > > <form name="myForm" method="POST" action="page.php">
        > > ...
        > > </form>
        > > <p><a href="javascript:document.myForm.submit();">Submit</a></p>
        > >
        > > Not sure I understand exactly what your problem is, other than that
        > -- can you elaborate or
        > > provide a link or source code?
        > >
        > > Are you looking to do something like this?
        > >
        > > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        > > "http://www.w3.org/TR/html4/loose.dtd">
        > > <html>
        > > <head>
        > > <meta http-equiv="Content-Type" content="text/html;
        charset=iso-8859-1">
        > > <title></title>
        > > </head>
        > > <body>
        > >
        > > <form action="<?php echo $PHP_SELF; ?>" method="POST">
        > > <?php
        > > for($i = 1; $i <= 5; $i++)
        > > {
        > > echo " <p>$i. <input type=\"submit\" name=\"submit$i\"
        > value=\"Button #$i\"></p>\n";
        > > }
        > > ?>
        > > </form>
        > >
        > > <?php
        > > foreach($_POST as $key => $value)
        > > {
        > > if(strpos($key, "submit") !== FALSE)
        > > {
        > > echo "<p>You pressed $value.</p>";
        > > break;
        > > }
        > > }
        > > ?>
        > >
        > > </body>
        > > </html>
        > >
        > > > Date: Fri, 04 Jun 2004 03:10:44 -0000
        > > > From: "Chuck" <caharris@r...>
        > > > Subject: Mozilla document.forms.submit() problem
        > > >
        > > > Hi all,
        > > > Maybe someone here can answer my question. (I may have missed
        > > > something somewhere, but so far I haven't found anything with
        LOTS of
        > > > searching.)
        > > >
        > > > background:
        > > > I've got an app (Linux/Mozilla
        1.0.1/Apache/PHP/mySQL/HTML/Javascript)
        > > > to be run on (WinXP/IE 6/Apache/PHP/etc.)
        > > >
        > > > problem:
        > > > (Due to browser differences, I've had a few "issues" with IE, all of
        > > > which have been overcome except this one.)
        > > >
        > > > The <BUTTON...> tag works completely different in IE from
        Mozilla, so
        > > > I have to resort to the older <INPUT type=...> format for a menu
        form,
        > > > and use an 'onclick=' javascript function that, at its end,
        calls the
        > > > document.forms.submit() method. HOWEVER, Mozilla doesn't pass any
        > > > POST fields for some reason. Everything works fine with the
        > > > <BUTTON...> tags (to the point I've got things), but it fails
        with the
        > > > <INPUT...> tags using the submit() method.
        > > >
        > > > NOTE: under IE, the text between the <BUTTON></BUTTON> tags is used
        > > > for the POST variable, instead of the 'value="foo"' attribute (like
        > > > it's supposed to do).
        > > >
        > > > Any ideas?
        > > >
        > > > (The only thing I can think of is, in my PHP code, to check for BOTH
        > > > values--the ones that Mozilla and IE will pass--but that is so
        > > > inefficient!)
        > > >
        > > > Thanks in advance.
      Your message has been successfully submitted and would be delivered to recipients shortly.