auto-submit form

Discussion in 'Javascript' started by Navillus, Feb 21, 2006.

  1. Navillus

    Navillus Guest

    Hey gang,

    I have a login form that is empty by default, but can be filled with
    values from a previous form:

    <input type=text maxlength="40" size="40" name="user" value="`usr`">
    <input type=password maxlength="8" name="password" value="`pss`">

    where usr and pss are sent from the previous form.

    I'd like to make a javascript function (I assume this is easy in
    javascript) that automatically submits the form when usr and pss exist.
    How would this be done?
    Navillus, Feb 21, 2006
    #1
    1. Advertising

  2. Navillus

    Navillus Guest

    Navillus wrote:
    > Hey gang,
    >
    > I have a login form that is empty by default, but can be filled with
    > values from a previous form:
    >
    > <input type=text maxlength="40" size="40" name="user" value="`usr`">
    > <input type=password maxlength="8" name="password" value="`pss`">
    >
    > where usr and pss are sent from the previous form.
    >
    > I'd like to make a javascript function (I assume this is easy in
    > javascript) that automatically submits the form when usr and pss exist.
    > How would this be done?


    Building on my previous post, I've looked up this much so far:
    In the header, I put:

    <head>
    <script language="javascript">
    function autoSubmit()
    {
    document.form.submit();
    }
    </script>
    </head>

    and then after the form, in the document, I put this:

    <script language="JavaScript">
    if (`usr`)
    {
    autoSubmit();
    }
    </script>


    Now, when usr is present, it should trigger the if statement to be
    true. And it is definatly showing up correctly; that is, when usr is
    absent, the if statement is empty, but if usr is present, the if
    statement is filled. But for some reason it isn't redirecting. Yikes!
    Navillus, Feb 21, 2006
    #2
    1. Advertising

  3. Navillus

    RobG Guest

    Navillus wrote:
    > Navillus wrote:
    >
    >>Hey gang,
    >>
    >>I have a login form that is empty by default, but can be filled with
    >>values from a previous form:
    >>
    >><input type=text maxlength="40" size="40" name="user" value="`usr`">
    >><input type=password maxlength="8" name="password" value="`pss`">
    >>
    >>where usr and pss are sent from the previous form.


    Then you have minimal security.


    >>I'd like to make a javascript function (I assume this is easy in
    >>javascript) that automatically submits the form when usr and pss exist.
    >>How would this be done?

    >
    >
    > Building on my previous post, I've looked up this much so far:
    > In the header, I put:
    >
    > <head>
    > <script language="javascript">


    The language attribute is deprecated, type is required.


    > function autoSubmit()
    > {
    > document.form.submit();


    You have a form named 'form'?

    > }
    > </script>
    > </head>
    >
    > and then after the form, in the document, I put this:
    >
    > <script language="JavaScript">
    > if (`usr`)


    That will always be true. Taken literally, you are asking if 'usr' is
    not undefined, which it isn't so the test returns true.

    Presuming that 'usr' is your shorthand for a reference to the value of
    the input named 'user', then (based on the posted HTML) it will have a
    value of - 'usr' - (quotes included) and so that will return true too.


    > {
    > autoSubmit();
    > }
    > </script>
    >
    >
    > Now, when usr is present, it should trigger the if statement to be


    No, it will always be true so it will try to submit the form immediately
    regardless.


    > true. And it is definatly showing up correctly; that is, when usr is
    > absent, the if statement is empty, but if usr is present, the if
    > statement is filled. But for some reason it isn't redirecting. Yikes!


    What you have shown is an attempt to call the submit method of a form
    with name/id of 'form'.

    You haven't shown the actual form, how you try to get and insert values
    for 'usr' or 'pss', or even what it is supposed to do onsubmit (what is
    the value of the action attribute? does it use POST or GET?) so a
    statement about what might happen when the submit method is called is
    speculation.


    --
    Rob
    RobG, Feb 22, 2006
    #3
  4. Navillus

    Navillus Guest

    RobG wrote:
    > Navillus wrote:
    > > Navillus wrote:
    > >
    > >>Hey gang,
    > >>
    > >>I have a login form that is empty by default, but can be filled with
    > >>values from a previous form:
    > >>
    > >><input type=text maxlength="40" size="40" name="user" value="`usr`">
    > >><input type=password maxlength="8" name="password" value="`pss`">
    > >>
    > >>where usr and pss are sent from the previous form.

    >
    > Then you have minimal security.
    >
    >
    > >>I'd like to make a javascript function (I assume this is easy in
    > >>javascript) that automatically submits the form when usr and pss exist.
    > >>How would this be done?

    > >
    > >
    > > Building on my previous post, I've looked up this much so far:
    > > In the header, I put:
    > >
    > > <head>
    > > <script language="javascript">

    >
    > The language attribute is deprecated, type is required.
    >
    >
    > > function autoSubmit()
    > > {
    > > document.form.submit();

    >
    > You have a form named 'form'?
    >
    > > }
    > > </script>
    > > </head>
    > >
    > > and then after the form, in the document, I put this:
    > >
    > > <script language="JavaScript">
    > > if (`usr`)

    >
    > That will always be true. Taken literally, you are asking if 'usr' is
    > not undefined, which it isn't so the test returns true.
    >
    > Presuming that 'usr' is your shorthand for a reference to the value of
    > the input named 'user', then (based on the posted HTML) it will have a
    > value of - 'usr' - (quotes included) and so that will return true too.
    >
    >
    > > {
    > > autoSubmit();
    > > }
    > > </script>
    > >
    > >
    > > Now, when usr is present, it should trigger the if statement to be

    >
    > No, it will always be true so it will try to submit the form immediately
    > regardless.
    >
    >
    > > true. And it is definatly showing up correctly; that is, when usr is
    > > absent, the if statement is empty, but if usr is present, the if
    > > statement is filled. But for some reason it isn't redirecting. Yikes!

    >
    > What you have shown is an attempt to call the submit method of a form
    > with name/id of 'form'.
    >
    > You haven't shown the actual form, how you try to get and insert values
    > for 'usr' or 'pss', or even what it is supposed to do onsubmit (what is
    > the value of the action attribute? does it use POST or GET?) so a
    > statement about what might happen when the submit method is called is
    > speculation.
    >
    >
    > --
    > Rob


    Here's the jist of what I got so far. Something is still tripping it up
    so it can't submit:

    <script language="JavaScript">
    function savecookie()
    {
    /* save the values of user and password of the form input
    (document.form.elementname) in the cookie */
    var url = "/sap/its/iacproject/select_premises.html";
    var nextyear = new Date();
    nextyear.setFullYear(nextyear.getFullYear() + 1);
    document.cookie = 'password= '+ document.Login.password.value +
    '# expires='+ nextyear.toGMTString() +'; path= /';
    document.cookie = 'user= '+ document.Login.user.value + ';
    expires=' + nextyear.toGMTString() +'; path= /';
    }

    function autoSubmit(){
    document.Login.submit();
    }
    </script>



    </head>

    <body `SAP_BodyAttributes()` onload="`SAP_OnloadJavaScript()`">

    <form name="Login" action="">

    <table border=0 cellpadding=0 cellspacing=0 width=100%>
    <br>
    <br>
    <tr>
    <td width=5%></td>
    <td>
    <table border=0 cellpadding=2 cellspacing=2>
    <tr>
    <td align=right class=label>`#LoginID`
    </td>
    <td align=left>
    <input type=text maxlength="40" size="40" name="user"
    value="`usr`">
    </td>
    </tr>
    <tr>
    <td align=right class=label>`#Password`
    </td>
    <td align=left>
    <input type=password maxlength="8" name="password" value="`pss`">
    </td>
    </tr>

    <tr>
    <td></td>
    <td>


    <input type=image name="~OkCode(LGON)"
    SRC="`mimeURL(~name="button/login.gif")`" border=0

    onclick="savecookie();">

    </td>

    </tr>

    </table>

    `if (~messageline != "")`

    <table border=0>
    <tr>
    <td align=center class=message>`~messageline`
    </td>
    </tr>
    </table>

    `end`


    </td>
    </tr>

    </form>


    <script language="JavaScript">
    var testUser = `usr`;
    if (testUser != "")
    {
    savecookie(); <-- not sure if I should call this function, which
    the normal form seems to do
    autoSubmit(); <-- or this guy right here, neither seem to work
    }
    </script>

    <script> document.Login.user.focus(); </script>
    <p>

    </p>
    </body>

    </html>


    Now, there's some wierd SAP variable stuff in there, but trust me, when
    the previous form sends the variable 'usr', calling `usr` puts it in
    there correctly. It doesn't seem to matter though. I've tried like 5
    different ways to test to see if usr exists, and none of them seem to
    work. In fact, even if I just do something like if (1), it still won't
    automatically submit. Well, it did once, but only when there wasn't a
    value of usr. I'm thinking something like the <script>
    document.Login.user.focus(); </script> is preventing it from
    auto-submitting. I dont know. All help is appreciated. Thanks
    Navillus, Feb 22, 2006
    #4
  5. Navillus

    RobG Guest

    Navillus wrote:
    > RobG wrote:
    >
    >>Navillus wrote:
    >>
    >>>Navillus wrote:
    >>>
    >>>
    >>>>Hey gang,
    >>>>
    >>>>I have a login form that is empty by default, but can be filled with
    >>>>values from a previous form:
    >>>>
    >>>><input type=text maxlength="40" size="40" name="user" value="`usr`">
    >>>><input type=password maxlength="8" name="password" value="`pss`">
    >>>>
    >>>>where usr and pss are sent from the previous form.

    >>
    >>Then you have minimal security.
    >>
    >>
    >>
    >>>>I'd like to make a javascript function (I assume this is easy in
    >>>>javascript) that automatically submits the form when usr and pss exist.
    >>>>How would this be done?
    >>>
    >>>
    >>>Building on my previous post, I've looked up this much so far:
    >>>In the header, I put:
    >>>
    >>><head>
    >>><script language="javascript">

    >>
    >>The language attribute is deprecated, type is required.
    >>
    >>
    >>
    >>> function autoSubmit()
    >>> {
    >>> document.form.submit();

    >>
    >>You have a form named 'form'?
    >>
    >>
    >>> }
    >>></script>
    >>></head>
    >>>
    >>>and then after the form, in the document, I put this:
    >>>
    >>><script language="JavaScript">
    >>> if (`usr`)

    >>
    >>That will always be true. Taken literally, you are asking if 'usr' is
    >>not undefined, which it isn't so the test returns true.
    >>
    >>Presuming that 'usr' is your shorthand for a reference to the value of
    >>the input named 'user', then (based on the posted HTML) it will have a
    >>value of - 'usr' - (quotes included) and so that will return true too.
    >>
    >>
    >>
    >>> {
    >>> autoSubmit();
    >>> }
    >>></script>
    >>>
    >>>
    >>>Now, when usr is present, it should trigger the if statement to be

    >>
    >>No, it will always be true so it will try to submit the form immediately
    >>regardless.
    >>
    >>
    >>
    >>>true. And it is definatly showing up correctly; that is, when usr is
    >>>absent, the if statement is empty, but if usr is present, the if
    >>>statement is filled. But for some reason it isn't redirecting. Yikes!

    >>
    >>What you have shown is an attempt to call the submit method of a form
    >>with name/id of 'form'.
    >>
    >>You haven't shown the actual form, how you try to get and insert values
    >>for 'usr' or 'pss', or even what it is supposed to do onsubmit (what is
    >>the value of the action attribute? does it use POST or GET?) so a
    >>statement about what might happen when the submit method is called is
    >>speculation.
    >>
    >>
    >>--
    >>Rob

    >
    >
    > Here's the jist of what I got so far. Something is still tripping it up
    > so it can't submit:
    >
    > <script language="JavaScript">


    The language attribute is (still) deprecated, type is required.

    <script type="text/javascript">


    > function savecookie()
    > {
    > /* save the values of user and password of the form input
    > (document.form.elementname) in the cookie */
    > var url = "/sap/its/iacproject/select_premises.html";


    The 'url' variable is not used - is it supposed to be?


    > var nextyear = new Date();
    > nextyear.setFullYear(nextyear.getFullYear() + 1);
    > document.cookie = 'password= '+ document.Login.password.value +
    > '# expires='+ nextyear.toGMTString() +'; path= /';
    > document.cookie = 'user= '+ document.Login.user.value + ';
    > expires=' + nextyear.toGMTString() +'; path= /';


    Don't let your code auto-wrap. Manually wrap at about 70 characters or
    errors like this are introduced.

    From what you have posted, the value of 'user' will be - `usr` - and
    the value of password will be - `pss` - always (presuming that the form
    does actually auto-submit). I don't think that is what is intended.

    You don't appear to ever get values for user and password from the
    cookie (or anywhere else) to put into the form.


    > }
    >
    > function autoSubmit(){
    > document.Login.submit();
    > }
    > </script>
    >
    >
    >
    > </head>
    >
    > <body `SAP_BodyAttributes()` onload="`SAP_OnloadJavaScript()`">


    That is invalid HTML. `SAP_BodyAttributes()` is an attribute value with
    no name. You are feeding onload a string literal, whereas it requires a
    function call or script statements. The above also causes illegal
    character errors in Firefox unless the ` character is replaced with '.

    I get the feeling this is sever code that you are trying to generate
    client code from.


    > <form name="Login" action="">
    >
    > <table border=0 cellpadding=0 cellspacing=0 width=100%>
    > <br>
    > <br>
    > <tr>
    > <td width=5%></td>
    > <td>
    > <table border=0 cellpadding=2 cellspacing=2>
    > <tr>
    > <td align=right class=label>`#LoginID`
    > </td>
    > <td align=left>
    > <input type=text maxlength="40" size="40" name="user"
    > value="`usr`">


    The input has a value of the string literal `usr`. Nothing you have
    posted shows how any other value might get in there.


    > </td>
    > </tr>
    > <tr>
    > <td align=right class=label>`#Password`
    > </td>
    > <td align=left>
    > <input type=password maxlength="8" name="password" value="`pss`">


    The input has a value of the string literal `pss`. Nothing you have
    posted shows how any other value might get in there.


    > </td>
    > </tr>
    >
    > <tr>
    > <td></td>
    > <td>
    >
    >
    > <input type=image name="~OkCode(LGON)"


    Weird name, looks more like a function call.


    > SRC="`mimeURL(~name="button/login.gif")`" border=0


    More invalid HTML with incorrect nesting of quotes.


    >
    > onclick="savecookie();">
    >
    > </td>
    >
    > </tr>
    >
    > </table>
    >
    > `if (~messageline != "")`


    Is this supposed to be displayed in the page? More server code?

    >
    > <table border=0>
    > <tr>
    > <td align=center class=message>`~messageline`


    More server code?


    > </td>
    > </tr>
    > </table>
    >
    > `end`


    Ditto.


    > </td>
    > </tr>
    >
    > </form>
    >
    >
    > <script language="JavaScript">


    The language attribute is (still) deprecated, type is required.

    <script type="text/javascript">


    > var testUser = `usr`;
    > if (testUser != "")


    Considering that you initialise testUser with a string literal, this
    test will *always* be false. I suspect that the server is supplying a
    value for `usr`.


    > {
    > savecookie(); <-- not sure if I should call this function, which
    > the normal form seems to do


    Calling savecookie() makes no difference at all (I'll guess that the
    comment is there only for posting, it will cause an error if it's in the
    actual source).


    > autoSubmit(); <-- or this guy right here, neither seem to work


    This will do nothing. The submit function (as posted previously) is:

    function autoSubmit()
    {
    document.form.submit();
    }


    There is no form called 'form', the one you want to submit is called
    'Login'. You should allow the form name to be passed to autosubmit() or
    just call submit from here:

    document.forms['Login'].submit();


    But given the stuff above, if that does work (it will never be called at
    present because the if test always fails) the page will continuously
    submit itself in a never-ending loop.


    > }
    > </script>
    >
    > <script> document.Login.user.focus(); </script>
    > <p>
    >
    > </p>
    > </body>
    >
    > </html>
    >
    >
    > Now, there's some wierd SAP variable stuff in there, but trust me, when
    > the previous form sends the variable 'usr', calling `usr` puts it in
    > there correctly. It doesn't seem to matter though. I've tried like 5
    > different ways to test to see if usr exists, and none of them seem to
    > work. In fact, even if I just do something like if (1), it still won't
    > automatically submit. Well, it did once, but only when there wasn't a
    > value of usr. I'm thinking something like the <script>
    > document.Login.user.focus(); </script> is preventing it from
    > auto-submitting.


    Unlikely. If the script works then the form will be submitted before
    that line is reached. If the form isn't submitted, then focus is put
    onto the 'user' input.


    > I dont know.


    Nor do I. Seems to me you are posting what you think the browser is
    getting based on munged server code (but maybe that's wrong). Use your
    browser's view source function to get the actual code received at the
    client, then you might have a chance of making it work.

    Otherwise little more help can be provided unless someone understands
    what should be happening with your server code.



    --
    Rob
    RobG, Feb 22, 2006
    #5
  6. Navillus wrote:

    > I have a login form that is empty by default, but can be filled with
    > values from a previous form: [...]


    You should have continued the corresponding thread, that would have
    explained much to those who were not familiar with your SAP template
    already.


    PointedEars
    Thomas 'PointedEars' Lahn, Feb 22, 2006
    #6
    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. davout
    Replies:
    2
    Views:
    2,081
    davout
    Dec 7, 2004
  2. ppcguy

    auto form submit on ENTER key

    ppcguy, Aug 6, 2005, in forum: HTML
    Replies:
    4
    Views:
    7,646
    Benjamin Niemann
    Aug 8, 2005
  3. mazdotnet

    Auto Form Submit

    mazdotnet, May 17, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    3,452
    bruce barker \(sqlwork.com\)
    May 17, 2006
  4. linkswanted
    Replies:
    1
    Views:
    905
  5. Replies:
    3
    Views:
    671
Loading...

Share This Page