viewing the form variables that are being submitted

Discussion in 'Javascript' started by yawnmoth, May 1, 2009.

  1. yawnmoth

    yawnmoth Guest

    <form action="">
    <input type="submit" name="a" value="Submit">
    <input type="submit" name="b" value="Save">
    </form>

    <script>
    function zzz() {
    var vars = '', e = this.elements;
    for (i=0;i<e.length;i++)
    vars+= e.name + '=' + e.value + '&';
    alert(vars);
    }

    for(i=0;f=document.forms;i++)
    f.onsubmit=zzz;
    </script>

    If you hit either submit button you'll get an alert box with
    "a=Submit&b=Save&" in it. The resultant URL, however, will only have
    one of them set. ie. "b=Save" or "a=Submit" but not both.

    My question is... is it possible, in javascript, to view not what
    form elements exist but what form variables will be submitted?

    My goal is to adapt this into a bookmarklet that I can use on
    arbitrary websites.
     
    yawnmoth, May 1, 2009
    #1
    1. Advertising

  2. On Fri, 01 May 2009 12:02:32 -0700, yawnmoth wrote:

    [ Form and code snipped ]

    > My question is... is it possible, in javascript, to view not what form
    > elements exist but what form variables will be submitted?
    >
    > My goal is to adapt this into a bookmarklet that I can use on arbitrary
    > websites.


    You might want to try reading this:

    http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/
    e4859563aabaf768/dec455c027d3154c?q=serialize+form&lnk=ol&
     
    Jeremy J Starcher, May 1, 2009
    #2
    1. Advertising

  3. On May 1, 12:02 pm, yawnmoth <> wrote:
    > If you hit either submit button you'll get an alert box with
    > "a=Submit&b=Save&" in it.  The resultant URL, however, will only have
    > one of them set.  ie. "b=Save" or "a=Submit" but not both.


    In any given form, only one input with type submit can be successful.
    Only controls that are successful will be submitted as part of the
    form data.

    http://www.w3.org/TR/html401/interact/forms.html#successful-controls
     
    Justin McConnell, May 1, 2009
    #3
  4. yawnmoth

    SAM Guest

    Le 5/1/09 9:02 PM, yawnmoth a écrit :
    > <form action="">
    > <input type="submit" name="a" value="Submit">
    > <input type="submit" name="b" value="Save">
    > </form>
    >
    > <script>
    > function zzz() {
    > var vars = '', e = this.elements;
    > for (i=0;i<e.length;i++)
    > vars+= e.name + '=' + e.value + '&';
    > alert(vars);
    > }
    >
    > for(i=0;f=document.forms;i++)
    > f.onsubmit=zzz;
    > </script>
    >
    > If you hit either submit button you'll get an alert box with
    > "a=Submit&b=Save&" in it. The resultant URL, however, will only have
    > one of them set. ie. "b=Save" or "a=Submit" but not both.


    Usually both (or all) submit buttons have same name, and it is the sent
    value that gives the information about which one was clicked.

    > My question is... is it possible, in javascript, to view not what
    > form elements exist but what form variables will be submitted?


    I think no.

    Except
    <input type=submit value="foo" onclick="alert(this.value)">

    > My goal is to adapt this into a bookmarklet that I can use on
    > arbitrary websites.


    With which navigator ?

    --
    sm
     
    SAM, May 2, 2009
    #4
    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. Eric Shin

    Form submitted

    Eric Shin, Jan 12, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    494
    Martha[MSFT]
    Jan 12, 2004
  2. SWu
    Replies:
    0
    Views:
    600
  3. ben
    Replies:
    0
    Views:
    1,093
  4. =?Utf-8?B?TWFyayBQYXJ0ZXI=?=

    Form still being submitted despite being invalid

    =?Utf-8?B?TWFyayBQYXJ0ZXI=?=, Jul 25, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    643
  5. mr. gone
    Replies:
    9
    Views:
    273
    Thomas 'PointedEars' Lahn
    Aug 30, 2009
Loading...

Share This Page