form.submit and Netscape.

Discussion in 'Javascript' started by Bob Bedford, Oct 5, 2004.

  1. Bob Bedford

    Bob Bedford Guest

    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="RedirectLogin" method="POST" action="login.php">
    <input type="hidden" name="LogType" value="ManageProfile">
    </form><script
    language="javascript">document.forms["RedirectLogin"].submit();</script>

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

    please help

    Bob
    Bob Bedford, Oct 5, 2004
    #1
    1. Advertising

  2. Bob Bedford wrote:

    > 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="RedirectLogin" method="POST" action="login.php">
    > <input type="hidden" name="LogType" value="ManageProfile">
    > </form><script
    > language="javascript">document.forms["RedirectLogin"].submit();</script>
    >
    > I've even tried with 'RedirectLogin', but it doesn't work either.


    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["RedirectLogin"].submit();
    }
    </script>

    and remove the inline tag.

    HTH
    - Markus
    Markus Fischer, Oct 5, 2004
    #2
    1. Advertising

  3. Bob Bedford

    VK Guest

    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='document.forms["RedirectLogin"].submit()';">
    VK, Oct 5, 2004
    #3
  4. Bob Bedford

    Bob Bedford Guest

    Hi both,

    Thanks for your answers.

    > Use onLoad event instead.
    >
    > <body onLoad='document.forms["RedirectLogin"].submit()';">


    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
    Bob Bedford, Oct 5, 2004
    #4
  5. Bob Bedford

    Lee Guest

    Bob Bedford said:
    >
    >Hi both,
    >
    >Thanks for your answers.
    >
    >> Use onLoad event instead.
    >>
    >> <body onLoad='document.forms["RedirectLogin"].submit()';">

    >
    >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 ?


    PHP can redirect to a new page without sending an intermediate
    page to the client. Just send them the login page.
    Lee, Oct 5, 2004
    #5
  6. Bob Bedford

    Grant Wagner Guest

    Bob Bedford wrote:

    > Hi both,
    >
    > Thanks for your answers.
    >
    > > Use onLoad event instead.
    > >
    > > <body onLoad='document.forms["RedirectLogin"].submit()';">

    >
    > 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


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

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

    or

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

    or

    <body>
    <!-- content -->
    <?php
    if (whateverYourConditionIs) {
    print "<script type=\"text/javascript\">";
    print "window.onload = function() {";
    print "document.forms['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 <>
    comp.lang.javascript FAQ - http://jibbering.com/faq
    Grant Wagner, Oct 5, 2004
    #6
  7. Bob Bedford

    Bob Bedford Guest

    "Lee" <> a écrit dans le message de
    news:...
    > Bob Bedford said:
    > >
    > >Hi both,
    > >
    > >Thanks for your answers.
    > >
    > >> Use onLoad event instead.
    > >>
    > >> <body onLoad='document.forms["RedirectLogin"].submit()';">

    > >
    > >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 ?

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


    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
    Bob Bedford, Oct 5, 2004
    #7
  8. Bob Bedford

    Bob Bedford Guest

    "Grant Wagner" <> a écrit dans le message de
    news:...
    > Bob Bedford wrote:
    >
    > > Hi both,
    > >
    > > Thanks for your answers.
    > >
    > > > Use onLoad event instead.
    > > >
    > > > <body onLoad='document.forms["RedirectLogin"].submit()';">

    > >
    > > 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

    >
    > How is it "long work" to include the onload event dynamically?
    >
    > <?php
    > if (whateverYourConditionIs) {
    > print "<body onload=\"document.forms['RedirectLogin'].submit();\">";
    > } else {
    > print "<body>";
    > }
    > ?>
    >
    > or
    >
    > <?php
    > print "<body" .
    > (whateverYourConditionIs ? "
    > onload=\"document.forms['RedirectLogin'].submit();\"" : "") .
    > " style=\"margin:1em;\"" .
    > ">";
    > ?>
    >
    > or
    >
    > <body>
    > <!-- content -->
    > <?php
    > if (whateverYourConditionIs) {
    > print "<script type=\"text/javascript\">";
    > print "window.onload = function() {";
    > print "document.forms['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.

    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
    Bob Bedford, Oct 5, 2004
    #8
  9. On Tue, 5 Oct 2004 16:46:55 +0200, Bob Bedford
    <> wrote:

    [snip]

    > 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.


    A PHP group would be a better place to ask:

    comp.lang.php
    alt.comp.lang.php

    Mike

    --
    Michael Winter
    Replace ".invalid" with ".uk" to reply by e-mail.
    Michael Winter, Oct 5, 2004
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Yashwant
    Replies:
    3
    Views:
    2,633
    Michael Winter
    May 4, 2004
  2. Keith Bowes

    Form submit from A tag with Netscape

    Keith Bowes, Jan 12, 2004, in forum: Javascript
    Replies:
    5
    Views:
    149
    Grant Wagner
    Jan 21, 2004
  3. Yashwant

    Form doesn't submit onUnload in Netscape

    Yashwant, May 3, 2004, in forum: Javascript
    Replies:
    3
    Views:
    107
    Michael Winter
    May 4, 2004
  4. viper81
    Replies:
    1
    Views:
    121
  5. Replies:
    3
    Views:
    666
Loading...

Share This Page