form.submit and Netscape.

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

    form.submit and Netscape.

    I've a code with redirect to a login page if nobody is registered. It works
    fine on IE6, but I'm trying with NS, and it doesn't work.

    Here is the code:

    <form name="RedirectL ogin" method="POST" action="login.p hp">
    <input type="hidden" name="LogType" value="ManagePr ofile">
    </form><script
    language="javas cript">document .forms["RedirectLo gin"].submit();</script>

    I've even tried with 'RedirectLogin' , but it doesn't work either.

    please help

    Bob



  • Markus Fischer

    #2
    Re: form.submit and Netscape.

    Bob Bedford wrote:
    [color=blue]
    > I've a code with redirect to a login page if nobody is registered. It works
    > fine on IE6, but I'm trying with NS, and it doesn't work.
    >
    > Here is the code:
    >
    > <form name="RedirectL ogin" method="POST" action="login.p hp">
    > <input type="hidden" name="LogType" value="ManagePr ofile">
    > </form><script
    > language="javas cript">document .forms["RedirectLo gin"].submit();</script>
    >
    > I've even tried with 'RedirectLogin' , but it doesn't work either.[/color]

    Use the javascript-console to catch errors like this (Tools / Web Development / JavaScript Console).

    You will get the message "Error: document.forms. RedirectLogin has no properties".

    That's because you have you javascript-code inline to execute as soon as the browser has reached that point. But no one can guarantee you (and this is what you are seeing) that the part of the page you're refering to is already properly initialized in the browser internals.

    Put your code in the onload-Handler, this ensures everything is loaded and that the form is accessible:

    <script type="text/javascript">
    window.onload = function() {
    document.forms["RedirectLo gin"].submit();
    }
    </script>

    and remove the inline tag.

    HTH
    - Markus

    Comment

    • VK

      #3
      Re: form.submit and Netscape.

      Netscape is traditionally slow in rendering forms (the payback for
      multi-platform support). It could be that the form object is not initialized
      by the moment of the function call, despite it comes after the form tag.

      Use onLoad event instead.

      <body onLoad='documen t.forms["RedirectLo gin"].submit()';">


      Comment

      • Bob Bedford

        #4
        Re: form.submit and Netscape.

        Hi both,

        Thanks for your answers.
        [color=blue]
        > Use onLoad event instead.
        >
        > <body onLoad='documen t.forms["RedirectLo gin"].submit()';">[/color]

        The code is generated by a PHP script that "redirect" only on some cases.
        It's quite a long work to change things. It's there an other way ?

        Bob


        Comment

        • Grant Wagner

          #5
          Re: form.submit and Netscape.

          Bob Bedford wrote:
          [color=blue]
          > Hi both,
          >
          > Thanks for your answers.
          >[color=green]
          > > Use onLoad event instead.
          > >
          > > <body onLoad='documen t.forms["RedirectLo gin"].submit()';">[/color]
          >
          > The code is generated by a PHP script that "redirect" only on some cases.
          > It's quite a long work to change things. It's there an other way ?
          >
          > Bob[/color]

          How is it "long work" to include the onload event dynamically?

          <?php
          if (whateverYourCo nditionIs) {
          print "<body onload=\"docume nt.forms['RedirectLogin'].submit();\">";
          } else {
          print "<body>";
          }
          ?>

          or

          <?php
          print "<body" .
          (whateverYourCo nditionIs ? "
          onload=\"docume nt.forms['RedirectLogin'].submit();\"" : "") .
          " style=\"margin: 1em;\"" .
          ">";
          ?>

          or

          <body>
          <!-- content -->
          <?php
          if (whateverYourCo nditionIs) {
          print "<script type=\"text/javascript\">";
          print "window.onl oad = function() {";
          print "document.f orms['RedirectLogin'].submit();";
          print "}";
          print "</script>";
          }
          ?>
          </body>

          I probably missed several hundred other ways of accomplishing what you want
          using PHP. This is what PHP (or any other server-side technology) is for, to
          _dynamically_ create content based on certain logic, conditions or data. The
          fact that the content PHP is generating is client-side JavaScript is
          irrelevant to PHP.

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

          Comment

          • Lee

            #6
            Re: form.submit and Netscape.

            Bob Bedford said:[color=blue]
            >
            >Hi both,
            >
            >Thanks for your answers.
            >[color=green]
            >> Use onLoad event instead.
            >>
            >> <body onLoad='documen t.forms["RedirectLo gin"].submit()';">[/color]
            >
            >The code is generated by a PHP script that "redirect" only on some cases.
            >It's quite a long work to change things. It's there an other way ?[/color]

            PHP can redirect to a new page without sending an intermediate
            page to the client. Just send them the login page.

            Comment

            • Bob Bedford

              #7
              Re: form.submit and Netscape.


              "Lee" <REM0VElbspamtr ap@cox.net> a écrit dans le message de
              news:cjua950gma @drn.newsguy.co m...[color=blue]
              > Bob Bedford said:[color=green]
              > >
              > >Hi both,
              > >
              > >Thanks for your answers.
              > >[color=darkred]
              > >> Use onLoad event instead.
              > >>
              > >> <body onLoad='documen t.forms["RedirectLo gin"].submit()';">[/color]
              > >
              > >The code is generated by a PHP script that "redirect" only on some cases.
              > >It's quite a long work to change things. It's there an other way ?[/color]
              >
              > PHP can redirect to a new page without sending an intermediate
              > page to the client. Just send them the login page.[/color]

              The problem is that I send user's datas trough POST vars, instead of GET, so
              the only way I've found to redirect to some pages with vars in POST, is to
              create a FORM with the vars and then submit it. Maybe there is a better way
              ?

              Bob


              Comment

              • Bob Bedford

                #8
                Re: form.submit and Netscape.


                "Grant Wagner" <gwagner@agrico reunited.com> a écrit dans le message de
                news:4162B117.7 5C781F6@agricor eunited.com...[color=blue]
                > Bob Bedford wrote:
                >[color=green]
                > > Hi both,
                > >
                > > Thanks for your answers.
                > >[color=darkred]
                > > > Use onLoad event instead.
                > > >
                > > > <body onLoad='documen t.forms["RedirectLo gin"].submit()';">[/color]
                > >
                > > The code is generated by a PHP script that "redirect" only on some[/color][/color]
                cases.[color=blue][color=green]
                > > It's quite a long work to change things. It's there an other way ?
                > >
                > > Bob[/color]
                >
                > How is it "long work" to include the onload event dynamically?
                >
                > <?php
                > if (whateverYourCo nditionIs) {
                > print "<body onload=\"docume nt.forms['RedirectLogin'].submit();\">";
                > } else {
                > print "<body>";
                > }
                > ?>
                >
                > or
                >
                > <?php
                > print "<body" .
                > (whateverYourCo nditionIs ? "
                > onload=\"docume nt.forms['RedirectLogin'].submit();\"" : "") .
                > " style=\"margin: 1em;\"" .
                > ">";
                > ?>
                >
                > or
                >
                > <body>
                > <!-- content -->
                > <?php
                > if (whateverYourCo nditionIs) {
                > print "<script type=\"text/javascript\">";
                > print "window.onl oad = function() {";
                > print "document.f orms['RedirectLogin'].submit();";
                > print "}";
                > print "</script>";
                > }
                > ?>
                > </body>
                >
                > I probably missed several hundred other ways of accomplishing what you[/color]
                want[color=blue]
                > using PHP. This is what PHP (or any other server-side technology) is for,[/color]
                to[color=blue]
                > _dynamically_ create content based on certain logic, conditions or data.[/color]
                The[color=blue]
                > fact that the content PHP is generating is client-side JavaScript is
                > irrelevant to PHP.[/color]
                Javascript can create dynamic <form> tag, as I send POST vars trough my
                pages. I want to avoid to show various datas from my site, so for
                redirecting, I've to create <form method="post"> and then submit it. If you
                have a better way to redirect with post vars, please let me know.

                Cheers.

                Bob


                Comment

                • Michael Winter

                  #9
                  Re: form.submit and Netscape.

                  On Tue, 5 Oct 2004 16:46:55 +0200, Bob Bedford
                  <bedford1@YouKn owWhatToDoHereh otmail.com> wrote:

                  [snip]
                  [color=blue]
                  > Javascript can create dynamic <form> tag, as I send POST vars trough my
                  > pages. I want to avoid to show various datas from my site, so for
                  > redirecting, I've to create <form method="post"> and then submit it. If
                  > you have a better way to redirect with post vars, please let me know.[/color]

                  A PHP group would be a better place to ask:

                  comp.lang.php
                  alt.comp.lang.p hp

                  Mike

                  --
                  Michael Winter
                  Replace ".invalid" with ".uk" to reply by e-mail.

                  Comment

                  Working...